我有一个图片流(目前是一个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