Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6182339
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T01:10:58+00:00 2026-05-24T01:10:58+00:00

I have a Model, which needs to be written to disk somehow and read

  • 0

I have a Model, which needs to be written to disk somehow and read afterwards (making a simple Java 2D game). Now, there’s a reference to Player, which has an insaneload of References to Blocks and Entities. In my project there are a HUGE amount of Entities and Blocks, and I really dont want to write a toString()/encode() then fromString()/decode()… The project is overdue anyway and over here its 4:05 AM :p.

So, what does a human in that situation do? Crawl here and ask about what Serialization does, and if it will work right away. I’m in the drama that it must work on the first go, no much space to experimenter, sadly.

The situation below needs to be entirely written to disk. Doable with a single serialize() function 😮 ?

Now, imagine this fictive classes(in reality I have 5800 lines of java code and a ton of intermixed data, that hurts)(no functions)(off the top of my head):

class InventorySlot { Object[] list; Class type; int quantity; }
class Inventory { InventorySlot[] slots; }

class Player { int hp; Inventory inv,palette; double x,y; }

enum Block { air, stone, cobble, dirt, etc; }
class Entity { double x,y,dir,speed,h,w; /*AND CUSTOMS! (derivers)*/ }   
class EntitySpriteAnimationPuf { Particle[] parts; final double friction, dir, dirnoise; Color color; } // final vars!
class World
{
    List<Chunk> chunks; // have an infinite map. each chunk is 64x64 Blocks.
    Entity[65535] entities; // I have a lot of entites, both types and later their instances.
}
class Model // target class to be entirely written down
{
    Player p;
    WindowManager wm; // Yes, i have my own GUI. Yes, it looks wonderful. Yes its got a lot of data... Yes, ouch.
    World w; // got this manually written down.
    Vector<String> terminal; // Dont want this to be serialized...
    boolean guiactive, pause;
    // And a few more...
}
// AND A LOT MORE. MORE. MORE. MORE. MORE. MORE. MORE. MORE. MORE. MORE. MORE. MORE. MORE.
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T01:10:58+00:00Added an answer on May 24, 2026 at 1:10 am

    here is what u need to do with to load/save java object (exception handling is ignored)

    make sure all the classes implement the Serializable interface

    one thing to know is that, if you changed any of the serialized classes, then

    most likely your “deserialization” will fail

    public void load() {
        FileInputStream filein = new FileInputStream("data");
        ObjectInputStream in = new ObjectInputStream(filein);
        Model model = (Model) in.readObject();
        in.close();
    }
    
    public void save() {
        ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream("data"));
        out.writeObject(model);
        out.close();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a model that represents a registration process, which needs to track the
I have a model Foo which have a ForeignKey to the User model. Later,
Here's what I'm trying to do, and failing... I have a File model which
I have a basic model in which i have specified some of the fields
I have an application A with a domain-model which is mapped to a database
I have a basic ActiveRecord model in which i have two fields that i
I have an ActiveRecord model, Foo , which has a name field. I'd like
I have an Auction model with several attributes, two of which are current_auction:boolean and
In my domain model I have an abstract class CommunicationChannelSpecification, which has child classes
I have a pre-existing c++ object model which represents the business layer tier of

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.