日期:2014-05-20  浏览次数:20670 次

二进制流读入不完全
处理TCP DUMP的时候

FileInputStream file = new FileInputStream(path1);
this.output = new BufferedWriter(new FileWriter(path2));
DataInputStream dis = new DataInputStream(file);

for (int t = 0; t < 4; t++) {
if ((c = dis.read()) != -1) {
result = intToByteArray(c, 1);
temp = temp + getHex(result);
i++;
} else
return (0);
}

总是提前就Return了 而且还每次都同一个位置停止
文件越大丢的越多

------解决方案--------------------
Java code
for (int t = 0; t < 4; t++) {
if ((c = dis.read()) != -1) {
result = intToByteArray(c, 1);
temp = temp + getHex(result);
i++;
} else
return (0);
}

------解决方案--------------------
Java code
for (int t = 0; t < 4; t++) {
if ((c = dis.read()) != -1) {
result = intToByteArray(c, 1);
temp = temp + getHex(result);
i++;
} else
return (0);
}

------解决方案--------------------
这也没办法看出来为什么返回-1啊