Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to append information to an existing file 1

Status
Not open for further replies.

RookThis

Technical User
Joined
Jul 27, 2002
Messages
195
Location
US
How do you go about appending information to an existing file using Java? It's a bit confusing and I need some guidance in understanding the process.

Thank you in advance for the assistance!
 
The second argument to the FileOutputStream constructor, which I assume you're using, is a flag specifying whether to append to the file.
(see
So in your case, you might have:
FileOutputStream out = new FileOutputStream(new File("log.txt"), true);

And then use something like DataOutputStream to output.
DataOutputStream dataOut = new DataOutputStream(out);
dataOut.writeInt(123);

Or maybe PrintWriter et al would suit, if you're writing text.

Check out for some better examples!
 
Thanks for the site information. It helped to get what I need. One question I still have. If I have a text file and say numbers and I want to delete an entry and update the file, is there a procedure for that in Java? I found some information about a seek parameter. Any suggestions?

Thanks
 
Options:
1. RandomAccessFile
2. java.sql - usinf text driver
3. java.util.regex
 
what's the structure of the text file?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top