java中object流如何读取文件中的多个对象 java中object流如何读取文件中的多个对象 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 readObject()读取对象:import java.io.*; import java.util.Date; public class ObjectSaver { public static void main(String[] args) throws Exception { ObjectOutputStream out = new ObjectOutputStream (new FileOutputStream("D:""objectFile.obj")); //序列化对象 Customer customer = new Customer("阿蜜果", 24); out.writeObject("你好!"); out.writeObject(new Date()); out.writeObject(customer); out.writeInt(123); //写入基本类型数据 out.close(); //反序列化对象 ObjectInputStream in = new ObjectInputStream (new FileInputStream("D:""objectFile.obj")); System.out.println("obj1=" + (String) in.readObject()); System.out.println("obj2=" + (Date) in.readObject()); Customer obj3 = (Customer) in.readObject(); System.out.println("obj3=" + obj3); int obj4 = in.readInt(); System.out.println("obj4=" + obj4); in.close(); } } class Customer implements Serializable { private String name; private int age; public Customer(String name, int age) { this.name = name; this.age = age; } public String toString() { return "name=" + name + ", age=" + age; } } 输出结果如下: obj1=你好! obj2=Sat Sep 15 22:02:21 CST 2007 obj3=name=阿蜜果, age=24 obj4=123 数据库连接问题 写过贪吃蛇代码的大哥帮忙提示一些东西 菜鸟求问 如何实现打印预览? java 中的按钮设置 为了这个问题将倾我所有!(帮顶,立结) 求助:怎样在主窗口之前显示登陆窗口??? 哪里有介绍java底层知识的书,或者其他文档及相关资料。 界面的代码求救 AWT事件(MouseAdaptor) java.lang.NoClassDefFoundError: com/microsoft/sqlserver/jdbc/SQLCollation错误 谁能帮忙解决下这个问题?关于文件读取和排序的问题
import java.util.Date; public class ObjectSaver {
public static void main(String[] args) throws Exception {
ObjectOutputStream out = new ObjectOutputStream
(new FileOutputStream("D:""objectFile.obj")); //序列化对象 Customer customer = new Customer("阿蜜果", 24);
out.writeObject("你好!");
out.writeObject(new Date());
out.writeObject(customer);
out.writeInt(123); //写入基本类型数据
out.close();
//反序列化对象 ObjectInputStream in = new ObjectInputStream
(new FileInputStream("D:""objectFile.obj")); System.out.println("obj1=" + (String) in.readObject());
System.out.println("obj2=" + (Date) in.readObject());
Customer obj3 = (Customer) in.readObject();
System.out.println("obj3=" + obj3);
int obj4 = in.readInt();
System.out.println("obj4=" + obj4);
in.close();
}
} class Customer implements Serializable {
private String name;
private int age;
public Customer(String name, int age) {
this.name = name;
this.age = age;
} public String toString() {
return "name=" + name + ", age=" + age;
}
}
输出结果如下: obj1=你好! obj2=Sat Sep 15 22:02:21 CST 2007 obj3=name=阿蜜果, age=24 obj4=123