Tuesday, 6 August 2013

OutputStreams in Java

OutputStreams in Java

I was looking through the documentation for FileOutputStream and
ObjectOutputStream, and I haven't seen any methods for moving the "write
pointer" to a specified spot (although I have seen a constructor for
completely rewriting ALL data in the file, and I have seen a constructor
for simply appending the writtenData to the end of the file. Are there any
OutputStreams that I could use that allow me to write anywhere?
Also, I have been having trouble with the ObjectInputStream. I wrote some
test code to test Object updating (what I really plan on doing is writing
an array of two JTables to a file, and updating that array when I receive
two JTables from a client). I have tried writing a String to a text file
(I don't think file extension matters to Java, but I could be wrong), and
for some reason, it seems that the ObjectInputStream that I was using is
erasing all the contents of the file! Does anyone know what might be
causing this to happen? (It seems to happen even when the only thing my
program is doing is reading the Strings via the ObjectInputStream.)

No comments:

Post a Comment