Jessie Staton

Greenhorn
+ Follow
since May 08, 2015
Jessie likes ...
Android IntelliJ IDE Chrome
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
3
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Jessie Staton

Carey,

Thank you so much! I changed the output to print out the exception itself, and found out that input stream gets corrupted on the second object: java.io.StreamCorruptedException: invalid type code: AC

I solved this by creating a new ObjectInputStream inside the while loop:


I also realized that I never actually append new data to my appendto string, so I changed

to be

All records are showing up now.
Once again, thank you so much for your help! I have, probably, spent 5 days trying to figure this out...
6 years ago
Sure, here is how an object gets written to file:



And here is how it is read back:



It reads the first object fine, then (when looping the second time around), it goes all the way to line 28, and then jumps to line 49.
Please see attached for a sample output I get.

Thank you!

6 years ago
Sorry, I forgot to add that the binary file shows all records and grows every time a new record is added, so I assume that output stream works fine.
6 years ago
Hi guys and girls!

I apologize if I am duplicating an existing topic - I could not find anything similar to what I am trying to do here.
Basically, this is my java final project, and I am having an issue with reading from binary file. I wrote a calendar interface, where a user selects a date that is then passed to an object Ek along with two other Strings. Ek is then written to the binary file "data.dat" (appended to the end of file). A user can then either add more records (Ek) or read records from file. Reading a single object back is fine, but with several objects it only reads the first one and then throws IOException.
I am not sure what I am doing incorrectly.

Could anyone help me with this, please?

Here is the code (run MainMenu) - sorry, it's a huge mess right now:











Thank you!
6 years ago