View Single Post
  #1 (permalink)  
Old 08-01-2007, 05:50 AM
jason27131 jason27131 is offline
Member
 
Join Date: Jul 2007
Posts: 18
jason27131 is on a distinguished road
how to edit lines.
right now, im trying to edit the text file. however, all it does is overwrite over the original file. I want the string i add to be added to the original file. Is there someway i can do this?

For example, the original text says "hi". I want to add "how are you to it", so it would say "hi. how are you."


Codesimilar to before)

import java.io.*;

public class FileAccess {

public void displayFile(String f) throws IOException {
FileReader fr = new FileReader(f);
BufferedReader br = new BufferedReader(fr);


f = br.readLine();
while (f != null) {
System.out.println(f);
f = br.readLine();
}
br.close();
fr.close();
}

public void writeToFile(String outfile, String s) throws IOException {
FileOutputStream fs = new FileOutputStream(outfile);
PrintStream p = new PrintStream(fs);
p.println(s);
p.close();
fs.close();
}
}
thanks again.
ps. srry for all these questions
Reply With Quote
Sponsored Links