Serializable读写类操作
import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.WriteAbortedException; public class Serializable_test { public static void main(String[] args) throws FileNotFoundException, IOException, ClassNotFoundException { stu stu=new stu(121, "eqwewq"); // Writeobj(stu); resetobj(); } public static void resetobj() throws ClassNotFoundException, IOException { ObjectInputStream objectInputStream=new ObjectInputStream(new FileInputStream("E:\\123.txt")); Object object=objectInputStream.readObject(); stu stu2=(stu)object; System.out.println(stu2); objectInputStream.close(); } public static void Writeobj(stu stu) throws IOException { ObjectOutputStream objectOutputStream=new ObjectOutputStream(new FileOutputStream("E:\\123.txt")); objectOutputStream.writeObject(stu); objectOutputStream.close(); } }