I/O 流:处理设备之间的数据的传输。Input是输入,Output是输出。输入输出指的是内存。所以Input对应的是Reader,指的是从外部读取数据进入内存(程序);Output对应的是Writer,指的是将内存中的数据写到外部;
分类:字节流(InputStream/OutputStream),字符流(Reader/Writer);
字符流专门用于处理文本文件,读取和写入字符使用
使用代码:
public class Main {
public static void main(String[] args) {
//路径path
String path1 = "D:\\study\\Java\\JavaSE基础\\TMP\\Test.txt";
String path2 = "D:\\study\\Java\\JavaSE基础\\TMP\\Test2.txt";
//1.输入字节流
//FileStream.ReadFile(path1);
//2.输出字节流
/* byte[] bytes = new byte[]{'a','b','c'};
FileStream.WriteFile(path1,bytes);*/
//3.输入字符流
//FileReaderAndWriter.ReadFile(path2);
//4.输出字符流
String value = "我是Java";
// FileReaderAndWriter.WriteFile(path2,value);
//5.输入字节流转字符流
/* try {
InputStreamReader reader = new InputStreamReader(new FileInputStream(new File(path1)));
} catch (Exception e) {
throw new RuntimeException(e);
}
//6.输出字节流转字符流
try {
OutputStreamWriter writer= new OutputStreamWriter(new FileOutputStream(new File(path1)));
} catch (FileNotFoundException e) {
throw new RuntimeException(e);
}*/
//7.缓冲输入字符流
//BuffedReaderAndWriter.ReadFile(path1);
//8.缓冲输出字符流
//BuffedReaderAndWriter.WriteFile(path2,value);
//9.利用缓冲流复制文件
//BuffedReaderAndWriter.copyFile(path1,path2);
//10.对象输出流,可以利用流持久化对象,但要求对象必须实现序列化接口Serializable接口
// People p = new Peop