ディレクトリ
シリアライズ(ObjectOutputStreamの)
シリアライゼーション:クラスは、バイナリデータ伝送に変換することができる(実装シリアライズクラスをシリアル化することができます)
ObjectOutputStreamの(序列化)を実装したOutputStream。
簡単な例:
class Animal implements Serializable{
private String eat;
private String write;
public Animal() {
}
public Animal(String eat, String write) {
this.eat = eat;
this.write = write;
}
public String getEat() {
return eat;
}
public void setEat(String eat) {
this.eat = eat;
}
@Override
public String toString() {
return "eat:" + this.eat + "、write:" + this.write;
}
}
public class Demo01 {
private static final File ANIMAL_FILE = new File("D:" + File.separator + "Hello.ses");
public static void main(String[] args) throws Exception {
test();
System.out.println(detest());
}
public static void test() throws Exception {
Animal an = new Animal("饭","水");
ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(ANIMAL_FILE));
oos.writeObject(an);
oos.close();
}
}
デシリアライズ(ObjectInputStreamの)
ObjectOutputStream.readObject()()によって情報出力をObjectOutputStream.writeObject読むことができます。
ObjectInputStreamの(序列化)を実装するInputStream
簡単な例:
public class Demo01 {
private static final File ANIMAL_FILE = new File("D:" + File.separator + "Hello.ses");
public static void main(String[] args) throws Exception {
detest();
}
public static void detest() throws Exception {
ObjectInputStream ois = new ObjectInputStream(new FileInputStream(ANIMAL_FILE));
Animal an = (Animal) ois.readObject();
System.out.println(an);
ois.close();
}
結果
eat:饭、write:水
シーケンス一般的な使用サードパーティの管理ツールの実際の開発は、構造化テキスト伝送に変えることができ、すべての言語を使用することができます。
過渡
過渡:オペレーションの自動シーケンスの過程で(通常は自動的に保存されている)、属性宣言を保存する必要があります。
簡単な例:
class Animal implements Serializable{
private transient String eat;
private transient String write;
public Animal() {
}
public Animal(String eat, String write) {
this.eat = eat;
this.write = write;
}
public String getEat() {
return eat;
}
public void setEat(String eat) {
this.eat = eat;
}
@Override
public String toString() {
return "eat:" + this.eat + "、write:" + this.write;
}
}
public class Demo01 {
private static final File ANIMAL_FILE = new File("D:" + File.separator + "Hello.ses");
public static void main(String[] args) throws Exception {
///test();
detest();
}
public static void test() throws Exception {
Animal an = new Animal("饭","水");
ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream(ANIMAL_FILE));
oos.writeObject(an);
oos.close();
}
public static void detest() throws Exception {
ObjectInputStream ois = new ObjectInputStream(new FileInputStream(ANIMAL_FILE));
Animal an = (Animal) ois.readObject();
System.out.println(an);
ois.close();
}
}
結果
一過性:データが保存されていません
eat:null、write:null