有IO就要Close
FileInputStream in=null;//定义一个管子
in=new FileInputStream("地址")//兑到目标文件,期间要捕获异常
输出
int b = 0;
FileInputStream in = null;
try {
in = new FileInputStream("f://TDDOWNLOAD//[Core.Java基础教程]_杨帆_Circular.java");
} catch (Exception e) {
System.out.println("找不到该文件");
System.exit(-1);
}
try {
long num = 0;
while ((b = in.read()) != -1 ) {//只要不等于-1就没有读完程序,最重要
System.out.println((char) b);//转换成字符
num++;
}
in.close();
System.out.println();
System.out.println("共读取了" + num + "个字符");
} catch (Exception e) {
System.out.println("文件读取错误");
System.exit(-1);