主题:[求助] 一个InputStream程序的问题。
import java.io.*;
public class Test {
public static void main(String[] args) {
FileInputStream in = null;
try {
in = new FileInputStream("c:\\Test.java"); // A
} catch (FileNotFoundException e) {
System.out.println("The File can't be found!");
System.exit(-1);
}
int b;
long num = 0;
try {
while((b = in.read())!= -1) {
System.out.print((char)b);
num ++;
}
in.close();
} catch (IOException e1) {
System.out.println("Erro when loading the file....");
System.exit(-1);
}
System.out.println();
System.out.println("The size of this file is: " + num);
}
}
C:/Test.java就是当前这个程序代码。为什么将A句改为
while((in.read())!= -1) {
b = in.read();
运行时,就显示一堆乱七八糟的字母?而如果不改,就是会正常显示。
public class Test {
public static void main(String[] args) {
FileInputStream in = null;
try {
in = new FileInputStream("c:\\Test.java"); // A
} catch (FileNotFoundException e) {
System.out.println("The File can't be found!");
System.exit(-1);
}
int b;
long num = 0;
try {
while((b = in.read())!= -1) {
System.out.print((char)b);
num ++;
}
in.close();
} catch (IOException e1) {
System.out.println("Erro when loading the file....");
System.exit(-1);
}
System.out.println();
System.out.println("The size of this file is: " + num);
}
}
C:/Test.java就是当前这个程序代码。为什么将A句改为
while((in.read())!= -1) {
b = in.read();
运行时,就显示一堆乱七八糟的字母?而如果不改,就是会正常显示。