Jump to content
  • Advertisement

Archived

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

role

[java] saving object files

This topic is 5736 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
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!