Home arrow static arrow Java Programming [Archive] - adding to the end of a file
Warning: Creating default object from empty value in /www/htdocs/w008deb8/wiki/components/com_staticxt/staticxt.php on line 51
Java Programming [Archive] - adding to the end of a file
This topic has 2 replies on 1 page.

Posts:38
Registered: 5/28/04
adding to the end of a file  
Aug 9, 2004 4:46 AM



 
hi guys,
im tryin to open a file then add changes to the end of it, at the mo im using the following but it doesnt add to the end, any ideas?

try {
BufferedReader br = new BufferedReader(new FileReader("H:
new folder
TransactionFile.txt"));
BufferedWriter bw = new BufferedWriter(new FileWriter("H:
new folder
TransactionFile.txt"));
while (br.readLine() != null) {
bw.newLine();
}
bw.write("Transaction started at: " + (new Date()));
bw.close();
br.close();
}
catch(Exception e){
System.out.println(e);
}
 

Posts:11,200
Registered: 7/22/99
Re: adding to the end of a file  
Aug 9, 2004 4:55 AM (reply 1 of 2)



 
Look up the documentation of FileWriter -- there is a constructor which lets you specify whether to append or not.
http://java.sun.com/j2se/1.4.2/docs/api/java/io/FileWriter.html
 

Posts:1,872
Registered: 2/12/03
Re: adding to the end of a file  
Aug 9, 2004 7:05 AM (reply 2 of 2)



 
you may also wants to look at Jakarta Common IO library. It's utility makes it easy to manupilate files contents.
 
This topic has 2 replies on 1 page.