java输入输出流是站在程序的角度来说的。从文件中读取数据用输入流,向文件中写数据用输出流。
package com.janson.day20180827;import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;public class TestFileInputStream {
public static void main(String[] args) {
FileInputStream in = null;
int f = 0;
try {
in = new FileInputStream(System.getProperty("user.dir") + "\\src\\com\\janson\\day20180827\\TestFileInputStream.java");
}catch (FileNotFoundException e) {
e.printStackTrace();
System.out.println("找不到指定文件");
System.exit(-1);
} try {
long num =0L;
while ((f=in.read()) != -1) {
System.out.print((char)f);
num ++;
}
System.out.println("一共读取了"+ num + "个字节");
}catch (IOException e) {
System.out.println("文件读取错误");
System.exit(-1);
}
}
}