java.io.ObjectOutputStream [1]
私はインスタンスのバイナリファイルを書き込みます。
メソッド
- writeObject - 指定オブジェクトをObjectOutputStreamに書き込む
例
import java.io.*; public class Main { public static void main(String[] args) throws Exception { Hero her = new Hero("yoosuke", 77, 18); //保存 ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("rpgsave.dat"); oos.writeObject(her); oos.close(); //復元 ObjectInputStream ois = new ObjectInputStream(new FileInputStream("rpgsave.dat"); Hero her2 = (Hero) ois.readObject(); ois.close(); } }