wood burning stoves 2.0*
The moose likes I/O and Streams and the fly likes writing in file at the end of file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » I/O and Streams
Bookmark "writing in file at the end of file" Watch "writing in file at the end of file" New topic
Author

writing in file at the end of file

ray bond
Ranch Hand

Joined: Oct 11, 2000
Posts: 111
hello there ,
I am writing in file using following code ,
it writes in file is ok but for every time it writes in file
and deletes previous information in file , how can I write in
file that whenever printwriter writes in file it starts writing
at the end of file , so previous information in file remain as
it is and it adds new information to file,
here is my code sippet in servlet,
File f1 = new File(strfile);
System.out.println("writing in file " + strfile);
FileWriter fwr = new FileWriter(f1);
BufferedWriter buff = new BufferedWriter(fwr);
PrintWriter output = new PrintWriter(buff);

System.out.println("got printwriter");
ServletInputStream sis = request.getInputStream();
DataInputStream dis = new DataInputStream(sis);
while((strwrite=dis.readLine())!=null)
{
System.out.println("strwrite = " + strwrite);
output.println( "=====from client=====" + strwrite);
System.out.println("servlet reply" + strwrite);
}
output.close();
so how can I write in file starting at the EOF (end of file).
thanks
Carl Trusiak
Sheriff

Joined: Jun 13, 2000
Posts: 3340
Use the constructor FileWriter(String fileName, boolean append)
Hope this helps


I Hope This Helps
Carl Trusiak, SCJP2, SCWCD
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
Ray's note had to be the longest version of: "How do I append to a file?" that I have ever seen!


Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
ray bond
Ranch Hand

Joined: Oct 11, 2000
Posts: 111
thanks carl and thomas ,
I gave my code here because some time replyers ask to post code and questions go on and on , so i decided to give every kind of information about my question , thanks anyway.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: writing in file at the end of file
 
Similar Threads
Writing Files in Tomcat?
System.out Arabic Text
append method
applet to servlet
Question about File, FileWriter + BufferedWriter