主要有两种方式区分:
1.以内存作为参照物按流向分:输入流和输出流
2.按照数据格式分:字节流(以Stream结尾)、字符流(以Reader/Writer结尾)
java.io包下的流,主要用的有以下几个:
文件专属:
FileInputStream:
FileInputStream fis = new FileInputStream("C:\\Users\\lenovo\\Desktop\\work\\test.txt");
FileOutputStream:
FileOutputStream fos = new FileOutputStream("C:\\Users\\lenovo\\Desktop\\work\\testcopy.txt");
FileRader:
FileReader fir = new FileReader("C:\\Users\\lenovo\\Desktop\\work\\test.txt");
FileWriter:
FileWriter fiw = new FileWriter("C:\\Users\\lenovo\\Desktop\\work\\testcopy.txt");
转换流:
InputStreamReader:
BufferedReader buf = new BufferedReader(new InputStreamReader(new FileInputStream("C:\\Users\\lenovo\\Desktop\\work\\test.txt")));
OutputStreamReader:
BufferedInputStream bis = new BufferedInputStream(new FileInputStream());
缓冲流专属:
BufferedReader;
BufferedWriter;
BufferedInputStream;
BufferedOutputSteam;
数据流专属:
DateInputSteam;
DateOutputSteam;
标准输出流:
PrintWriter;
PrintStream;
对象专属流:
ObjectInputStream;
ObjectOutputStream;
注意,流在使用完后均需要close,一般写在finally()方法中,输出流需要还需要flush
如果是包装流与节点流关系的话,将包装流关闭,后默认关闭节点流。