Results 1 to 5 of 5
Thread: IOStreams
- 01-22-2008, 03:02 PM #1
Member
- Join Date
- Nov 2007
- Posts
- 50
- Rep Power
- 0
IOStreams
Hi all,
please see below code...
It successfully writes data from abc.txt to xyz.txt.Java Code:import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; public class ChracterStreams { public static void main(String[] args) throws IOException { FileReader in=null; FileWriter out=null; try { in=new FileReader("E:/Documents and Settings/Naresh/Desktop/java/abc.txt"); out=new FileWriter("E:/Documents and Settings/Naresh/Desktop/java/xyz.txt"); int c; while((c=in.read())!=-1) out.write(c); } finally { if(in!=null) in.close(); if(out!=null) out.close(); } } }
but it overwrites data in xyz.txt.
I just want to append new data in abc.txt to the data in xyz.txt.
now what i have to do ?
anyone please tell me....
Thankq very much.
- 01-22-2008, 05:33 PM #2
Member
- Join Date
- Jan 2008
- Posts
- 6
- Rep Power
- 0
Just use different constructor
FileWriter has an other constructor where you can specify whether to append or overwrite.
use
out=new FileWriter("E:/Documents and Settings/Naresh/Desktop/java/xyz.txt",true);
the boolean true will set that to append mode.
- 01-22-2008, 08:57 PM #3
Member
- Join Date
- Nov 2007
- Posts
- 50
- Rep Power
- 0
thankq very much
- 01-22-2008, 10:46 PM #4
Ahh thanks for that information XiaoXiao. I never knew that. That will come in handy!!! =]
- 01-23-2008, 05:46 AM #5
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,374
- Blog Entries
- 1
- Rep Power
- 18


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks