• Advertisement

Archived

This topic is now archived and is closed to further replies.

[java] saving object files

This topic is 5497 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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

Share this post


Link to post
Share on other sites
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();

Share this post


Link to post
Share on other sites

  • Advertisement