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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

FileOutputStream problem

Status
Not open for further replies.

D4VEHUG

Technical User
Mar 5, 2004
6
0
0
GB
Can anyone tell me how to open an existing file to use with a FileOutputStream?
I have the code below and can send output via pw...

String logPath = File.separator + "d:/retrieved07" + File.separator;
FileOutputStream f= new FileOutputStream(logPath + "logfile.dat");
PrintWriter pw = new PrintWriter(f);

What I want to do is be able to add to "logfile.dat" without it being re-created when I run the program.

Many thanks to anyone who can help me.
 
You cannot *open* a file with FileOutputStream - this is for writing. You need a FileInputStream to *open* a file - hence reading.

You can however, append to an existing file using different IO streams than you have used like so :
Code:
FileWriter fr = new FileWriter("myfile.name", true);
fw.write("hello");


In future you may wish to post to forum269 as this forum is somewhat redundant these days ...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top