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

  • Home
  • SEARCH
  • 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 6738205
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T11:20:21+00:00 2026-05-26T11:20:21+00:00

I have saved an arrayList into a binary file by using serialastion. How do

  • 0

I have saved an arrayList into a binary file by using serialastion. How do I now retrieve this data from the binary file?

This is the code I have used for serialisation

public void createSerialisable() throws IOException
{
    FileOutputStream fileOut =  new FileOutputStream("theBkup.ser");
    ObjectOutputStream out =  new ObjectOutputStream(fileOut);
    out.writeObject(allDeps);
    options();
}

and this the code I am trying to use for deserialization of the arrayList:

public void readInSerialisable() throws IOException
{
    FileInputStream fileIn = new FileInputStream("theBKup.ser");

    ObjectInputStream in = new ObjectInputStream(fileIn);

    try
    {
     ArrayList readob  = (ArrayList)oi.readObject();  
               allDeps = (ArrayList) in.readObject();
    }
    catch (IOException exc)
    {
        System.out.println("didnt work");
    }
}

allDeps is the declared array list in the classes constructer. Im trying to save the arrayList from the file to the arrayList declared in this class.

  • 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-26T11:20:21+00:00Added an answer on May 26, 2026 at 11:20 am

    Your code is mostly correct, but there is one mistake and a couple of things that might make it work better. I’ve highlighted them with asterisks (since, apparently, I can’t make them bold in ‘code’ mode).

    public void createSerialisable() throws IOException
    {
        FileOutputStream fileOut =  new FileOutputStream("theBkup.ser");
        ObjectOutputStream out =  new ObjectOutputStream(fileOut);
        out.writeObject(allDeps);
        **out.flush();** // Probably not strictly necessary, but a good idea nonetheless
        **out.close();** // Probably not strictly necessary, but a good idea nonetheless
        options();
    }
    
    public void readInSerialisable() throws IOException
    {
        FileInputStream fileIn = new FileInputStream("theBKup.ser");
    
        ObjectInputStream in = new ObjectInputStream(fileIn);
    
        try
        { 
            **// You only wrote one object, so only try to read one object back.**
            allDeps = (ArrayList) in.readObject();
        }
        catch (IOException exc)
        {
            System.out.println("didnt work");
            **exc.printStackTrace();** // Very useful for findout out exactly what went wrong.
        }
    }
    

    Hope that helps. If you still see a problem then make sure you post the stack trace and a complete, self-contained, compilable example that demonstrates the problem.

    Note that I’ve assumed that allDeps contains objects that are actually Serializable and that your problem is in readInSerialisable rather than in createSerialisable. Again, a stack trace would be extremely helpful.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose, I have saved some permissions in the database by using this code: RoleRepository
I have saved data which was saved using NSUserDefaults. I was under the impression
I have saved an ArrayList to the session object. I am trying to retrieve
I've just saved an arraylist to a file. Now I want to load it
I have saved input from a textarea element to a TEXT column in MySQL.
I have saved a dataset in the sql database in an xml column using
I have some URLs in an Excel file which I have saved as a
I have a file saved as UCS-2 Little Endian I want to change the
I have a Spinner Control bind with data from Sqllite during the Page Load
Using reflection I have an object which I need to cast into an iterable

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.