0
我正在使用primefaces上傳圖像,剪裁圖像,然後在graphicImage上顯示最終圖像。Primefaces graphicImage流未關閉,文件鎖定
該過程工作正常,但問題是,當我檢索最終圖像顯示在graphicImage上時,流沒有關閉,文件被java.exe阻止,所以我遇到了問題例如在用戶註銷時刪除文件/目錄,因爲它只是一個臨時目錄。
這是我StreamedContent的消氣:
public StreamedContent getGraphicCropped() {
try{
if (newImageName != null) {
File file2 = new File(pathCroppedImage);
InputStream input = new FileInputStream(file2);
graphicCropped = new DefaultStreamedContent(input);
showImageFinal = true;
}
} catch(Exception e){
e.printStackTrace();
}
return graphicCropped;
}
如果我做input.close();
那麼我就能夠刪除的文件,但它沒有顯示出來,因爲我知道,這個調用getter時不止一次在生命週期。