This week's book giveaway is in the OO, Patterns, UML and Refactoring forum.
We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Help me about RandomAccessFile Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Help me about RandomAccessFile" Watch "Help me about RandomAccessFile" New topic
Author

Help me about RandomAccessFile

Milind Mahajan
Ranch Hand

Joined: Oct 23, 2000
Posts: 77
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

Joined: Nov 05, 2000
Posts: 7
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

Joined: Oct 23, 2000
Posts: 77
Hi,
Thanks a lot Andrews.
Thanks.
Milind
 
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
 
subject: Help me about RandomAccessFile
 
It's not a secret anymore!