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 8013379
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T19:37:06+00:00 2026-06-04T19:37:06+00:00

in my java Project I have several classes/java files but is in Menu class

  • 0

in my java Project I have several classes/java files but is in Menu class that is stored all the lists of stuff that is used. In terms of data I store 6 Lists(2 ArrayLists and 4 HashMaps) which 1 is defined in Menu class and others are in different classes.
So I need to create a savestate and a loadstate to when I close the program to restore the previous state. All the Lists are implemented with Serializable

Is it possible to save all the Menu’s state and reload it or I’ve to save all the lists individually? Save all in one file would be great.

Here is the function I have, works(no warnings/errors) and compiles but doesn’t creates the file “datafiles“.

Any ideas?

    private void MenuSave(){
    String wd = System.getProperty("user.dir");

    JFileChooser fc = new JFileChooser(wd);
    int rc = fc.showDialog(null, "Select Data File Location to Save");

    if (rc == JFileChooser.APPROVE_OPTION)
    {
    File file = fc.getSelectedFile();
    String filename = file.getAbsolutePath();

    savestate(lf, lc, lv, lcl,filename);}
    }


public void savestate(Cars la, Bikes l2, Motos l3, Planes l4, People n1, Food n2, String filename){

    int i;
    File out = new File(filename);

    ObjectOutputStream output = null;

    try{
        output = new ObjectOutputStream(new FileOutputStream(filename));
        for(Car c : la.getCars().values()){
            output.writeObject(c);
        }
        for(Bike b : l2.getBikes().values()){
            output.writeObject(b);
        }
        for(Moto m : l3.getMotos().values()){
            output.writeObject(m);
        }
        for(i=0;i<n1.size();i++)
        {output.writeObject(n1.get(i)));
        }
        for(i=0;i<n2.size();i++)
        {output.writeObject(n2.get(i)));
        }


    }catch (FileNotFoundException ex) {
        ex.printStackTrace();
    } catch (IOException ex) {
        ex.printStackTrace();
    } finally {
        try {
            if (output != null) {
                output.flush();
                output.close();
            }
        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }
}
  • 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-06-04T19:37:07+00:00Added an answer on June 4, 2026 at 7:37 pm

    So as I thought I just need to save the lists individually without that for .
    1-Choose where to save the file, then save the Classes in there.
    2-To read just parse the input and store replacing the current Classes.
    …

        String wd = System.getProperty("user.dir");
        this.setAlwaysOnTop(false);
        JFileChooser fc = new JFileChooser(wd);
    
        fc.setDialogType((int)JFileChooser.SAVE_DIALOG);
    
    
        int rc = fc.showDialog(null, "Select Data File");
        this.setAlwaysOnTop(true);
    
        if (rc == JFileChooser.APPROVE_OPTION)
        {
        File file = fc.getSelectedFile();
    
        ObjectOutputStream output = null;
    
        try{
        output = new ObjectOutputStream(new FileOutputStream(file));
        output.writeObject(list1);
        output.writeObject(list2);
        output.writeObject(list3);
        ....
    
    
        output.close();
    
        }catch (IOException x){
         ....
        }catch(NullPointerException n){
         ....    
        }}
    

    to read is just the same:

        String wd = System.getProperty("user.dir");
        this.setAlwaysOnTop(false);
        JFileChooser fc = new JFileChooser(wd);
        fc.setDialogType((int)JFileChooser.OPEN_DIALOG);
        int rc = fc.showDialog(null, "Select Data File to Load");
        this.setAlwaysOnTop(true);
    
        if (rc == JFileChooser.APPROVE_OPTION)
        {
        File file = fc.getSelectedFile();
        String filename = file.getAbsolutePath();
    
    
        ObjectInputStream input = null;
        try{
        input = new ObjectInputStream(new FileInputStream(file));
        this.list1=(ListType1)input.readObject();
        this.list2=(ListType2input.readObject();
        ....
        }catch (IOException x){
          ...  
    
        }catch(ClassNotFoundException x){
          ...
        }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If I have a java project that consists of several different types of files
I have a Java project in Eclipse with ~10 packages and ~10 class files
I have several Java files that have Japanese strings in them, and are encoded
So I have this Java project made up of several classes, some external JAR
I have a project that includes some Java APIs, some resource files, and some
I have inherited a Java project which includes a number of classes that are
I have an application that uses several different Java classes and would like to
I have a Java project with all source files in the src folder. This
I have a Java project that needs a addon interface. I was thinking about
I have a Java project that I'm trying to implement with a model-view-controller design.

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.