[java] saving object files

Started by
0 comments, last by role 21 years, 2 months ago
is it possible to save group of class object? like this: i have a class that hold : object position : int x,y object image number : int pic object hp : int hp object float : boolean floAt object visible : boolean visiBle and something that refer to another object : MainObject mainObject and then another class : map size : Dimension dimension link to another map : String warp i want to save a group of these two classes object, and later i can erase the one that i don''t use. plz show me a link for saving & loading file or a code maybe to save these classes i have lack knowledge for IO file thank you
-------------Golden T Game Engine - Java Game EngineGolden T Website | Golden T Forum
Advertisement
If you''re simply looking to save a class file to the hard drive, take a look at serialization:

http://java.sun.com/docs/books/tutorial/essential/io/serialization.html

Serialization allows you to write data from a class file such that you can later reconstruct the object. Here''s an example of how to save an object:

  MyClass mclass = new MyClass();FileOutputStream out = new FileOutputStream("datafile");ObjectOutputStream str = new ObjectOutputStream(out);str.writeObject(mclass);str.flush();   

This topic is closed to new replies.

Advertisement