File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes I/O and Streams and the fly likes Problem with RandomAccessFile Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "Problem with RandomAccessFile" Watch "Problem with RandomAccessFile" New topic

Problem with RandomAccessFile

Andreas Groscurth

Joined: Mar 08, 2004
Posts: 12

can anyone tell my why I do get -1393754107 with this code instead of 1

Jim Yingst

Joined: Jan 30, 2000
Posts: 18671
Because an ObjectOutputStream writes a header, too. Take a look at the size of the file that's been written - it's bigger than just the 4 bytes that writeInt() would give you. You really don't want to read this with anything other than an ObjectInputStream. Or in this case, if you're not going to use writeObject() and readObject() at some point, there's really no need to be using the ObjectOutput streams at all.

"I'm not back." - Bill Harding, Twister
I agree. Here's the link:
subject: Problem with RandomAccessFile
It's not a secret anymore!