File update!!
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Mustapha_Abella
Posted On:   Thursday, June 14, 2001 06:29 AM

Hi there I have a question regarding reading files and writing to files. I am using BufferedReader and BufferedWrited to acheive both. My question is: Can I write to a file without having to override it? here is the code I am using if it can be helpful: import java.io.*; public class Test1 { public static void main(String args[]){ String str; try { BufferedReader br = new BufferedReader(new FileReader("test.txt")); BufferedWriter bw = new BufferedWriter(new FileWriter("test1.txt")); while ((str = br.readLine()) != null) { bw.write(str + System.getProperty(   More>>

Hi there



I have a question regarding reading files and writing to files. I am using BufferedReader and BufferedWrited to acheive both. My question is: Can I write to a file without having to override it?



here is the code I am using if it can be helpful:



import java.io.*;

public class Test1 {

public static void main(String args[]){

String str;

try {

BufferedReader br = new BufferedReader(new FileReader("test.txt"));

BufferedWriter bw = new BufferedWriter(new FileWriter("test1.txt"));

while ((str = br.readLine()) != null) {

bw.write(str + System.getProperty("line.separator"));}

bw.flush();

br.close();

bw.close();}

catch (FileNotFoundException fnfe){
System.out.println(fnfe);
return;}

catch (IOException ioe){
System.out.println(ioe);}

}}



So in the example above is it possible to copy 'test.txt' to 'test1.txt' without overriding 'test1'!!??


I would be grateful for any help I can get.
Thanks in advance.    <<Less

Re: File update!!

Posted By:   Michael_Wax  
Posted On:   Thursday, June 14, 2001 10:36 AM

I believe that you want to use the RandomAccessFile class, which will allow you to append your text, rather than overwrite the existing text.
About | Sitemap | Contact