Results 1 to 2 of 2
  1. #1
    jason27131 is offline Member
    Join Date
    Jul 2007
    Rep Power

    Default 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."

    Code:(similar to before)


    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) {
    f = br.readLine();

    public void writeToFile(String outfile, String s) throws IOException {
    FileOutputStream fs = new FileOutputStream(outfile);
    PrintStream p = new PrintStream(fs);
    thanks again.
    ps. srry for all these questions

  2. #2
    brianhks is offline Senior Member
    Join Date
    Jul 2007
    Rep Power


    Change your code to this
    Java Code:
    FileOutputStream fs = new FileOutputStream(outfile, true);
    The "true" tells it to append to the file instead of overwriting it.

Similar Threads

  1. how can we remove blank lines from a .txt
    By Camden in forum New To Java
    Replies: 12
    Last Post: 07-29-2011, 01:38 PM
  2. How To Edit/Add JSP Pages in NetBeans IDE
    By JavaForums in forum NetBeans
    Replies: 2
    Last Post: 02-17-2009, 12:14 PM
  3. Replies: 0
    Last Post: 04-06-2008, 07:45 PM
  4. Can't edit JTextField after modal dialog
    By JavaNerd in forum Java Applets
    Replies: 0
    Last Post: 02-07-2008, 10:11 PM
  5. Doubt in edit and delete methods
    By ai_2007 in forum Advanced Java
    Replies: 3
    Last Post: 07-01-2007, 11:40 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts