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;
}
}
这是一些问题所在的部分。我得到这个输出长度_img:3147850 [B@72d86c58我在这里是为了最后一个块2122j的值是2122incre值是3145728我的值是384并且计数的值是496bublo......如果你注意到的值对应该是 2122,而不是 496,这就是文件损坏的原因。