怎样写一个类描述学生,并将几个学生的信息能序列化到文件中保存,并能再次读出来? 怎样写一个类描述学生,并将几个学生的信息能序列化到文件中保存,并能再次读出来? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 public static void main(String[] args) throws FileNotFoundException, IOException, ClassNotFoundException { Student s1 = new Student("Tom", 18); Student s2 = new Student("Jerry", 19); ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("aa.txt")); oos.writeObject(s1); oos.writeObject(s2); oos.close(); ObjectInputStream ois = new ObjectInputStream(new FileInputStream("aa.txt")); Student sa1 = (Student)ois.readObject(); Student sa2 = (Student)ois.readObject(); ois.close(); System.out.println(sa1.getName() + "\t" + sa1.getAge()); System.out.println(sa2.getName() + "\t" + sa1.getAge());}Student 类需要实现 java.io.Serializable 。不知道是这个意思吗? ip地址的正则 一个简单问题---关于Point类的setLocation方法 why 在java的桌面程序,一个界面里如何实现点击几个字即打开IE到一个网址;或者点菜单即可打开IE到一个网址? java打开URL地址获得返回的 BigDecimal问题 jfreeChart纵坐标轴问题 为什么我getConnection时候不能用变量,必须要用写好的字符串、 想学习JAVA但是不知从何学起 初学者问题 跟着那篇MyEclipse+struts+Hibernate的教程学。。 关于多态的问题
Student s1 = new Student("Tom", 18);
Student s2 = new Student("Jerry", 19);
ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("aa.txt"));
oos.writeObject(s1);
oos.writeObject(s2);
oos.close();
ObjectInputStream ois = new ObjectInputStream(new FileInputStream("aa.txt"));
Student sa1 = (Student)ois.readObject();
Student sa2 = (Student)ois.readObject();
ois.close();
System.out.println(sa1.getName() + "\t" + sa1.getAge());
System.out.println(sa2.getName() + "\t" + sa1.getAge());
}Student 类需要实现 java.io.Serializable 。不知道是这个意思吗?