我有一個圖片流(目前是一個PNG,但它可能是別的東西),我想將它轉換爲一個文件。 問題:流不entierely閱讀: 從中流來的初始畫面約20KB,而壓軸的文件是16架B 這裏是我的代碼:Java輸入流沒有完全讀取
...
fileImageOutput = new FileImageOutputStream(_templateFile);
int read = 0;
byte[] bytes = new byte[1024];
while ((read = imageStream.read(bytes)) != -1) {
fileImageOutput.write(bytes, 0, read);
}
}
catch(IOException ioe)
{
throw ioe;
}
finally
{
if(fileImageOutput!=null)
fileImageOutput.close();
if(imageStream!=null)
imageStream.close();
}
非常感謝你的幫助。
薩科
在其中創建您的輸入流可以插入代碼?還有你做任何檢查,看看這16個字節是什麼,看看他們是否與圖像文件的前16個字節? –
首先讀取文件的內容並在屏幕上打印並打開使用的文件檢查內容的差異 –
在關閉文件之前對流進行調用沖洗 – Stefan