Results 1 to 4 of 4

Thread: How to append an existing file in Java?

  1. #1
    Join Date
    May 2008
    Posts
    28

    How to append an existing file in Java?

    Hi,

    As I said earlier I am new with JAVA. I want a code to add text to an existing file in java.
    I mean I want to append to a file through java program.
    How to append an existing file in Java?

  2. #2
    Join Date
    Apr 2008
    Posts
    68

    Re: How to append an existing file in Java?

    It is actually very simple all you ne4ed to do is just add append option.

    Code:
    new FileOutputStream(f, true /* append */);
    I hope you got this.

  3. #3
    Join Date
    Apr 2008
    Posts
    44

    Re: How to append an existing file in Java?

    Append To File

    You can use the class FileWriter and BufferedWriter to append the data to a file.

    BufferedWriter

    The BufferWriter class is used to write text to a character-output stream, buffering characters so as to provide for the efficient writing of single characters, arrays, and strings.

    Try This:

    Code:
    import java.io.*;
    class FileWrite 
    {
       public static void main(String args[])
      {
          try{
        // Create file 
        FileWriter fstream = new FileWriter("out.txt",true);
            BufferedWriter out = new BufferedWriter(fstream);
        out.write("Hello Java");
        //Close the output stream
        out.close();
        }catch (Exception e){//Catch exception if any
          System.err.println("Error: " + e.getMessage());
        }
      }
    }

  4. #4
    Join Date
    Apr 2008
    Posts
    51

    Re: How to append an existing file in Java?

    java append text to file

    Code:
    try {
    BufferedWriter out = new BufferedWriter(new FileWriter("filename", true));
    out.write("aString");
    out.close();
    } catch (IOException e) {}

Similar Threads

  1. How to append data to a text file in java?
    By KALANI84 in forum Software Development
    Replies: 4
    Last Post: 05-02-2010, 04:44 PM
  2. Append text to end of file
    By New ID in forum Software Development
    Replies: 5
    Last Post: 18-01-2010, 09:35 AM
  3. Replies: 3
    Last Post: 16-07-2009, 01:29 PM
  4. About keyword Append in SQL
    By Ebenezer in forum Software Development
    Replies: 2
    Last Post: 11-04-2009, 11:11 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,518,541.25658 seconds with 16 queries