Java file
1.编码:
GBK
UTF-8
UTF-16
2. file类
1).java.io.file类表示文件(目录)
2).只用于表示文件/目录的信息(大小,名称),不能访问文件。
3. RandomAccessFile ———访问文件
4.字节流
IO流——字节流,字符流
1). 抽象类InputStream,OutputStream
2). EOF = End (读到-1)
3). 输入流
int b = in.read();
in.read(byte[] buf);
in.read(byte[] buf, int strat, int size)
4). 输出流
out.write(int b);
out.write(byte[] buf);
out.write(byte[] buf, int strat, int size);
5). 子类FileInputStream
6). 子类FileOutputStream
7). DataInputStream / DataOutputStream
对“流”功能的扩展,操作类型数据
DataOutputStream
writeInt(), writeDouble(), WriteUTF()
8). BufferedInputStream / BufferedOutputStream
提供缓冲区,提高IO性能
5. 字符流
1). 编码
2). 文本与文件
文本(char),16位无符号整数,Unicode编码(双字节编码)
文件,byte byte …… 的数据序列
文本文件:文本(char)序列按照某种编码方式(UTF-8,gbk)序列化为byte的存储结果
3). 字符流抽象类:Reader, Writer ——操作的是文本文件
字符处理,一次处理一个字符;字符底层是字节序列
字符流的基本实现:
InputStreamReader:byte流 ——> char流 ,按编码解析
OutputStreamWriter: char流 ——> byte流,按编码处理
文件读写流:FileReader, FileWriter ——对文件直接进行字符流的读写
4). 字符流的过滤器
BufferedReader ------------> readline
BufferedWriter/PrintWriter ------------> write line
6. 对象的序列化、反序列化
1). 对象序列化:将Object对象转化为Byte序列
2).序列化流(ObjectOutputStream),过滤流-----------writeObject
反序列化流(ObjectInputStream)--------------readObject
3).序列化接口Serializable:对象必须实现序列化接口,才能进行序列化
4). transient关键字:
5).子类和父类中序列化函数的调用