I have taken in a text file and converted it into a binary by writing the objects to a binary file, then i am attempting to read from the binary file, which works all the way through till the last record and then it throws the IO exception and never gets to my last print statement.
Below is my code that is triggering the error
try
{
ObjectInputStream objinputStream2 = new ObjectInputStream(new FileInputStream("binaryFile"));
for (int run = 0; run<count;count++)
{
Record readone = (Record) objinputStream2.readObject();
System.out.print(readone);
System.out.println("");
}
System.out.println("Reading completed for all" + count + " records. ");
// objinputStream2.close();
}
catch(FileNotFoundException e){ // Catches object
System.out.println("Sorry File not found"); // Error Message
}
catch(ClassNotFoundException e){ // Catches object
System.out.println("Sorry class not found"); // Error Message
}
catch(IOException e){ // Catches object
System.out.println("Problem with file output."); // Error Message
e.printStackTrace();
}
any help is appreciated
Stack trace:
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at bluej.runtime.ExecServer$3.run(ExecServer.java:730)
count
being populated? You may have fewer records in the file than you think.