流 就是指一连串流动的字符,以先进先出的方式发送信息的通道;
File 类
文件可以认为是相关记录或放在一起的数据的集合;
在 Java 中, 使用 java.io.File 类对文件进行操作;

绝对路径: 是从盘符开始的路径;
相对路径:是从当前路径开始的路径;

字节流
处理 二进制 文件 比较合适,比如图片之类的;
字节输入流 InputStream
字节输出流 OutputStream


FileInputStream
从文件系统中的某个文件中获得输入字节;
用于读取诸如 图像数据 之类的 原始字节流;

示例


FileOutputStream


文件拷贝

缓冲流
读取速度更快
缓冲输入流 BufferedInputStream
缓冲输出流 BufferedOutputStream
缓冲区满了执行 write,不满需要执行 flush 或者 close 清空缓存区;

字符流
它和字节流的用途不同,字节流更多的是处理 二进制的;
字符输入流 Reader
字符输出流 Writer


字节字符转换流
InputStreamReader
OutputStreamWriter


对象序列化
序列化: 把 Java 对象转换为字节序列的过程(写的过程);
反序列化: 把字节序列恢复为 Java 对象的过程(读的过程)。
步骤
1 创建一个类, 继承 Serializable 接口;
2 创建对象;
3 将对象写入文件;
4 从文件读取对象信息。
对象输入流 ObjectInputStream
对象输出流 ObjectOutputStream


网友评论