Java????????л???????л????
???????????? ???????[ 2013/5/2 9:59:15 ] ????????
???????????????????????????????????????????????????????????????????????????????????е?????????????????????????????Java??????????????У?????????????????????????????????????????Java????
??????Java??????????????е??????????????л???
????????????л???Java???????????????????л???
????????????л???????????????
????1??????????????е???浽?????????????????????У?
????2???????????????????????С?
???????JDK????е????л?API
????java.io.ObjectOutputStream??????????????????writeObject(Object obj)???????????????obj??????????л????????????????д??????????????С?
????java.io.ObjectInputStream???????????????????readObject()?????????????????ж????????У????????????л??????????????????
????????????Serializable??Externalizable?????????????????л???Externalizable???????Serializable???????Externalizable????????????????????????л???????????????Serializable???????????????????л???? ??
???????????л????????2??裺
????1??????????????????????????????????????????????????????????????
????2????????????????writeObject()????д????
???????????л?????????£?
????1???????????????????????????????????????????????????????????????
????2?????????????????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;
}
}
?????????????£?
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11