62,614
社区成员
发帖
与我相关
我的任务
分享
public class AA implements Serializable{
int x = 5;
int y = 6;
.........
}
FileOutputStream fos = new FileOutputStream("C:\\...");
ObjectOutputStream out = new ObjectOutputStream(fos);
AA a = new AA();
out.writeObject(a);
//这样a中的变量就保存下来了,只是变量,不保存方法的
//读取时
FileInputStream fis = new FileInputStream("C:\\...");
ObjectInputStream in = new ObjectInputStream(fis);
AA a = (AA)in.readObject();
//可以取a中的值了