Object流 Java对象的序列化过程
类实现了 Serializable 接口 是JDK自动实现了序列化过程
externalizable接口 是手动实现序列化过程
import java.io.*;
public class Test20180527{
public static void main(String args[])throws Exception {
T s1 = new T();
s1.i = 9;
FileOutputStream fos = new FileOutputStream("H:\\Test\\Test20180527.dat");
ObjectOutputStream oos = new ObjectOutputStream(fos); //Object输出流
oos.writeObject(s1);
oos.flush();
oos.close();
FileInputStream fis = new FileInputStream("H:\\Test\\Test20180527.dat");
ObjectInputStream ois = new ObjectInputStream(fis); //Object输入流
T tReaded = (T)ois.readObject();
System.out.println(tReaded.i +" "+ tReaded.j+" "+ tReaded.l);
}
}
class T implements Serializable{ // Serializable 标记
transient int i = 5; // transient 透明的
int j = 10;
int l = 3;
}
//输入输出流的字节抽象类
//输入输出流的字符抽象类
//对文件读写的字节流
//对文件读写的字符流
//带缓冲区输入,输出字节流
//带缓冲区输入,输出字符流
//对内存中的字节数组进行读写
//转换流,字节转换为字符
//数据流,直接写基础的数据类型及unionkode字符串 UTF8
//打印流
Object流