This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Agile forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Help me about RandomAccessFile

 
Milind Mahajan
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have a question on RandomAccessFile class in java.io package.
Using this class if we open a exisitng file in "rw" mode and write some data ,it always seems to overwrite the existing file. Am I right ? Is there any way to make it append to a file ?
Thanks
Milind
 
Andrew Edmonds
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, it will overwrite because on opening the file the pointer will always be set at the beginning of the file. To append you need to move the pointer to the end of the file first before writing:
If f is your file reference then
f.seek(f.length()); should do it.
Andrew
 
Milind Mahajan
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Thanks a lot Andrews.
Thanks.
Milind
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic