类要进行序列化/反序列化 Serializable接口 (序列化接口)
静态static和瞬态 transient都不能序列化
反序列化: FileInputStream对象--ObjectInputStream(ObjectInputStream fis):--readObject方法
序列化 把对象写出到文件中,进行持久化保存
FileOutputStream--ObjectOutputStream(ObjectOutputStream,fos)-writeObject(p)
反序列化:把文件中的字节内容读取出来,封装成一个对象
FileInputStream对象--ObjectInputStream(ObjectInputStream fis):--readObject方法
### 序列号冲突异常
果
public class Person implements Serializable {
private static final long serialVersionUID = 42336677L;
private String name;
public int age;
}
PrintWriter类: 是Writer的子类,Writer的方法,它都有
构造方法: PrintWriter(OutputStream os)/(Writer w) /(File path) (String path):
使用特有方法: println(Xxx yyy): 原样输出带换行 print(Xxx yyy): 原样输出不带换行
特点: 1.带自动刷新 2.方法不会抛出异常
*/
public class Demo04PrintWriter {
public static void main(String[] args) throws FileNotFoundException {
PrintWriter pw = new PrintWriter("day12_xw\\pw.txt");
pw.println(97);
pw.println(true);
pw.println('A');
pw.write(65);
pw.close();
}
}