Results 1 to 3 of 3
  1. #1
    bugger is offline Senior Member
    Join Date
    Nov 2007
    Posts
    111
    Rep Power
    0

    Default Text file over written

    I am trying to learn file handling in Java. I want to append text to the end of a file and tried following script:

    Java Code:
            BufferedWriter out = new BufferedWriter(new FileWriter("C:\\myFile.txt"));
            out.write("aString");
            out.close();
    But the text file is overwritten. I know I can use RandomAccessFile to point to end of file and then append. Is this possible with BufferedWriter?

  2. #2
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    8

    Default

    The FileWriter class api shows a couple of constructors that take a boolean append argument. You can find out what they do in the Constructor Detail section.

  3. #3
    bugger is offline Senior Member
    Join Date
    Nov 2007
    Posts
    111
    Rep Power
    0

    Default

    Thanks hardwired. It worked.

    Java Code:
    public FileWriter(String fileName,boolean append) throws IOException

Similar Threads

  1. count character in text file as input file
    By aNNuur in forum New To Java
    Replies: 7
    Last Post: 03-25-2010, 04:01 PM
  2. Search in text file
    By mark-mlt in forum New To Java
    Replies: 6
    Last Post: 04-03-2009, 04:33 PM
  3. How to read a text file from a Java Archive File
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 02-08-2008, 09:13 AM
  4. Reading text file
    By Lennon-Guru in forum New To Java
    Replies: 1
    Last Post: 12-15-2007, 11:38 PM
  5. Converting text file(.txt) to JPG file(.jpg) in java
    By javadeveloper in forum Advanced Java
    Replies: 0
    Last Post: 11-09-2007, 04:22 PM

Posting Permissions

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