怎样写一个类描述学生,并将几个学生的信息能序列化到文件中保存,并能再次读出来? 怎样写一个类描述学生,并将几个学生的信息能序列化到文件中保存,并能再次读出来? 解决方案 » 免费领取超大流量手机卡,每月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 。不知道是这个意思吗? package的编译运行问题~~~ synchronized相关 在一个线程里面要释放所以的资源(包括线程的资源)? 在图片上写字的问题 *.jar文件用来做什么,能直接运行吗? !!!请问怎样得出一个文件的内容? 如何让我的JFrame也支持滑轮滚动?用(jbwheel.jar和jbwheel.dll) 请问jsp怎么调用java的APPLICATION程序? 大家来讨论一下高级程序员(软件工程师)在软件开发过程中的作用问题 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 。不知道是这个意思吗?