import java.io.*;
public class TestFileInputStream {
public static void main(String[] args) {
int b = 0;
FileInputStream in = null;
try {
in = new FileInputStream("d:\\share\\java\\io\\TestFileInputStream.java");
} catch (FileNotFoundException e) {
System.out.println("找不到指定文件");
System.exit(-1);
}
try {
long num = 0;
while((b=in.read())!=-1){
System.out.print((char)b); /*就是此处,为什么用Integer的toString()方法不行呢,这里的强制转换为什么就可以编译了呢*/
num++;
}
in.close();
System.out.println();
System.out.println("共读取了 "+num+" 个字节");
} catch (IOException e1) {
System.out.println("文件读取错误"); System.exit(-1);
}
}
}问题在代码中的注释处~~~谢谢各位大虾指点啦~鄙人接触java不久,一直自学,很多困惑,进度也慢,望高人指点啊
public class TestFileInputStream {
public static void main(String[] args) {
int b = 0;
FileInputStream in = null;
try {
in = new FileInputStream("d:\\share\\java\\io\\TestFileInputStream.java");
} catch (FileNotFoundException e) {
System.out.println("找不到指定文件");
System.exit(-1);
}
try {
long num = 0;
while((b=in.read())!=-1){
System.out.print((char)b); /*就是此处,为什么用Integer的toString()方法不行呢,这里的强制转换为什么就可以编译了呢*/
num++;
}
in.close();
System.out.println();
System.out.println("共读取了 "+num+" 个字节");
} catch (IOException e1) {
System.out.println("文件读取错误"); System.exit(-1);
}
}
}问题在代码中的注释处~~~谢谢各位大虾指点啦~鄙人接触java不久,一直自学,很多困惑,进度也慢,望高人指点啊
b是int类型,属于内置类型,不是Integer类型。