import java.io.*;public class Main { public static void main(String[] args) throws Exception { String path = "./data.txt"; boolean append = false; ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(path, append)); oos.writeObject(new Person("张三", 18)); oos.writeInt(100); oos.writeUTF("quwgeuiy"); oos.close(); System.out.println("已经写入本地文件"); ObjectInputStream ois = new ObjectInputStream(new FileInputStream(path)); System.out.println(ois.readObject()); System.out.println(ois.readInt()); System.out.println(ois.readUTF()); ois.close(); }}class Person implements Serializable { private String name; private int age; public Person(String name, int age) { this.name = name; this.age = age; } @Override public String toString() { return "A{" + "age=" + age + ", name='" + name + '\'' + '}'; }}