为什么在int b哪里直接声明int b=in.read()后输出的数据未能进行进制转化?会连续出现 49 49 49 49不停止,而老师先声明b然后在while循环里赋上in.read()输出的字节码却没问题呢?
我所敲的不能进行转化,连续输出49……的代码:
FileInputStream in = new FileInputStream(fileName);
int b=in.read();
int i = 0;
while (b != -1) {
System.out.print(Integer.toHexString(b) + " ");
while (i++ % 10 == 0)
System.out.println();
}
in.close();
老师敲的没问题的代码:
FileInputStream in = new FileInputStream(fileName);
int b;
int i = 0;
while ((b = in.read()) != -1) {
System.out.print(Integer.toHexString(b) + " ");
while (i++ % 10 == 0)
System.out.println();
}
in.close();