• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

writing in file at the end of file

 
ray bond
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3341
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use the constructor FileWriter(String fileName, boolean append)
Hope this helps
 
Thomas Paul
mister krabs
Ranch Hand
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ray's note had to be the longest version of: "How do I append to a file?" that I have ever seen!
 
ray bond
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic