int count = 0;
byte[] buffer = new byte[8192]; // more if you like but no need for
int j = length_img % 8192;
int value = length_img - j;
int incre = 0;// it to be the entire file size
for (int i = 0; i < (value/8192) + 1; i++) {
if (length_img == incre + j) {
buffer = new byte[j];
int pair = dataInputStream.read(buffer);
System.out.print("i am here for last chunk" + buffer.length
+ "value of j is" + j + "incre value is" + incre
+ "the value of i is" + i
+ "and the value of count is" + pair);
image0OutFile.write(buffer, 0, pair);
break;
}
else {
count = dataInputStream.read(buffer);
image0OutFile.write(buffer, 0, count);
incre += 8192;
}
}
这正是一些问题lies.i正在此输出length_img部分:3147850 [B @ 72d86c58 我在这里对于j is2122incre价值的最后chunk2122value我的is3145728the值is384and count的值是496bublo ...如果你注意到pair的值应该是2122,而是它的496,这就是文件为什么会破坏的原因。写完整的内容到图像文件
我正在关闭流没有包括在代码中,但我这样做。问题是要更精确的值对image0OutFile.write(缓冲区,0,一对)的对变化;这里对的值与buffer.length.i相比有所改变,只是在打印后检查它 – 2013-03-23 10:04:50