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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T02:02:55+00:00 2026-06-07T02:02:55+00:00

I have a class that reads the written output of a Student[] array object

  • 0

I have a class that reads the written output of a Student[] array object

here is the code

import java.io.*;

// I use this class to read the final ouput "students_updated.dat"
public class StudentArrayObjectFileReader {

public static void main(String[] args) {
    try {
        ObjectInputStream fileReader = new ObjectInputStream(new FileInputStream("students_updated.dat"));
        Student[] studs = (Student[]) fileReader.readObject();
        fileReader.close();

        // List the records in console
        for (int i = 0; i < studs.length; i++) {
            System.out.printf("%7d %-35s %-5s %1d %-6s%n",studs[i].getID(), studs[i].getName(), studs[i].getCourse(), studs[i].getYr(), studs[i].getGender());
        }
    } catch (FileNotFoundException fnfe) {

        fnfe.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }
 }
}

problem is that it has an error when reading the Student[] studs = (Student[]) fileReader.readObject();

as stated here

java.io.EOFException
at java.io.ObjectInputStream$BlockDataInputStream.peekByte(ObjectInputStream.java:2571)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1315)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:369)
at StudentArrayObjectFileReader.main(StudentArrayObjectFileReader.java:9)

any idea on what could be the problem? Thanks in advance..

this is how the students_updated.dat was written

    public void saveStudentArray() { // studs print to student_updated.dat
    try{
        output.writeObject(studs); // write the final studs
        output.close();
    }catch(Exception e){
        e.printStackTrace();
    }
}

with its ObjectInputStream declared in the constructor of where this method is

  • 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-07T02:02:56+00:00Added an answer on June 7, 2026 at 2:02 am

    Check the contents of the students_updated.dat file. readObject() function expects the file to contain a serialized object.

    Does the file contain a serialized object? Check if the serialization succeeded without anything going wrong?

    If you’re trying to construct the array from a plain text file, you should not use readObject().

    Visit this link for a sample of how to serialize and deserialize an array – Can I serialize an array directly…

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

Sidebar

Related Questions

I have written a class(es) that writes and reads from hdfs. Given certain conditions
I have a java code like this: private class Uploader implements Runnable { //
I have written a program that reads in a File object (really an XML
Problem in words: For my application, I have a class that reads from a
I have a large-ish project that contains one class that reads from a file
I am new to Java. I just read that class variables in Java have
I have class that looks like this: class A { public: class variables_map vm
I've written this little test class to connect up to an FTP server. import
I have written a small class, which reads out annotation from methods. Now I
Kind of looking for affirmation here. I have some hand-written code, which I'm not

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.