1.反射获取对象
2.对象序列化与反序列化
package com.cj.test1; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; public class TestSerializable { public static void main(String[] args) throws FileNotFoundException, IOException, ClassNotFoundException { User user = new User(); user.setName("崔佳"); user.setGender("男"); user.setAge(27); ObjectOutputStream os = new ObjectOutputStream(new FileOutputStream("Temp")); os.writeObject(user); os.close(); System.out.println("输出完成"); ObjectInputStream is = new ObjectInputStream(new FileInputStream("Temp")); User user1 = (User) is.readObject(); System.out.println(user1.getName()+"==="+user1.getGender()+"==="+user1.getAge()); } }