This week's book giveaway is in the Agile forum.
We're giving away four copies of Head First Agile and have Andrew Stellman & Jennifer Greene on-line!
See this thread for details.
Win a copy of Head First Agile this week in the Agile forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

RandomAccessFile not fast enough?! / Wait for a stream  RSS feed

 
Michael Adams
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello,

i am developing an application which processes a file multiple times.

At first I generate a TIFF Image with Java Image I/O API which works perfectly well. Then I am re-reading the file to modify some pointers and stuff and this is where my problem starts:

The RandomAccessFile used for writing the file to the HD is still writing down the file when I am trying to re-read it and when I use want to write to the file I get an EOFException. The reason is obvious: The file is not entirely written to the Harddisk so it ends earlier than expected.

My question is: how can I wait for the randomaccessfile to complete the work before i go on? Or is there some better way to save the Data in memory before writing to the disk?

br

Michael Adams
 
Joe Ess
Bartender
Posts: 9429
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should call flush() when you are finished writing to a file. That tells the VM to write remaining data to the disk.
 
Michael Adams
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thanks for the reply but in fact that does not help either :-( I still get an EOFException.
 
Joe Ess
Bartender
Posts: 9429
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Then the problem isn't what you think it is. Without source code I can only speculate, but I'd bet you are writing data within the file and thinking that the file expands to accomodate it. It does not. Writing data anywhere but the end of a random access file replaces the existing data.
 
Michael Adams
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
thank you for your fast reply. it was not the fault of the randomaccessfile, it was a ******* TIFF pointer pointing to a field outside of the file ;-)

sorry for the inconvenience

br
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!