This week's book giveaway is in the General Computing forum.
We're giving away four copies of Arduino in Action and have Martin Evans, Joshua Noble, and Jordan Hochenbaum on-line!
See this thread for details.
The moose likes Java in General and the fly likes how adding text in a file (not rewriting the hole file) Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "how adding text in a file (not rewriting the hole file) " Watch "how adding text in a file (not rewriting the hole file) " New topic
Author

how adding text in a file (not rewriting the hole file)

Wall Schnok
Greenhorn

Joined: May 31, 2001
Posts: 8
i know only the classical
try
{ String pippo="C:\\myfile.txt";
FileOutputStream fos = new FileOutputStream(myfile);
OutputStreamWriter osw = new OutputStreamWriter(fos);
osw.write("text inside my file");
osw.flush();
fos.close();
}
catch(Exception e)
{
System.out.println("Error here !!!");
}
but this one clear my file and rewrite it , but I need to add text in an existing file .
thank you.
Wall Schnok
Greenhorn

Joined: May 31, 2001
Posts: 8
I did it .
It's
FileOutputStream fos = new FileOutputStream(myfile,true);
It was that "true" that missed .....
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
- thanks for letting us know .


"JavaRanch, where the deer and the Certified play" - David O'Meara
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: how adding text in a file (not rewriting the hole file)
 
Similar Threads
unicode problem in HTMLEditorKit
Character encoding using Java
OutputStreamWriter
Coversion of ResultSet
Split a File According to a String in the File