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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T16:28:47+00:00 2026-06-06T16:28:47+00:00

I am saving out and loading mixed data types. I either have the saving

  • 0

I am saving out and loading mixed data types. I either have the saving part wrong or the loading part wrong. I am using buffered serial save and load method.
Variable lastFetchDate is defined as a string and initialized as “00/00/00”.
It throws an error when reloading the data after it has been saved. What is wrong? I would have thought the opposite to writeBytes would be readBytes for a string.

Saving is as follows:

  FileOutputStream fos = new FileOutputStream("userPrefs.dat"); 
  BufferedOutputStream bos = new BufferedOutputStream(fos);   
  ObjectOutputStream oos = new ObjectOutputStream(bos);
  oos.writeBytes(lastFetchDate);
  // I close all streams

Loading is as follows:

  FileInputStream fis = new FileInputStream("userPrefs.dat"); 
  BufferedInputStream bis = new BufferedInputStream(fis);   
  ObjectInputStream ois = new ObjectInputStream(bis);
  lastFetchDate=(String)ois.readObject();  //<<<<< Error thrown here
  // I close all streams
  • 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-06T16:28:50+00:00Added an answer on June 6, 2026 at 4:28 pm

    You have written string as byte[] so need to read as byte[]

        byte [] bString = new byte[lastFetchDate.length()*2];
        ois.readFully(bString, 0, bString.length);
    

    Or if you write as Object using writeObject method then you can read as object,

    oos.writeObject(lastFetchDate);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have data objects with methods for loading, saving, updating data. Then I have
When saving a new entity something strange happens... I have a data grid with
i have a problem with saving something and am officially out of ideas. what
I know there are some solutions out there for saving and loading images on
I'm loading and saving out images with PIL just fine but I can't seem
So I've been using a compact data type in c++, and saving from memory
I'm been trying to figure out this serialize hashtable and saving/loading to disk business
Ok, I recently implemented a background worker to perform saving and loading of data.
I'm loading a prop and saving it File propfile=new File(getClass().getResource(credentials.properties).toURI()); prop.load(new FileInputStream(propfile)); prop.setProperty(a, username);
When saving a form I deactivate the save button to avoid double submission. Save

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.