Results 1 to 7 of 7
  1. #1
    fatabass is offline Senior Member
    Join Date
    Nov 2011
    Location
    Turkey
    Posts
    380
    Blog Entries
    24
    Rep Power
    4

    Default Why can't I append to text file with JAVA ?

    Hi everyone;

    Java Code:
    		PrintWriter myWriter = new PrintWriter(new FileOutputStream("c:/try.txt"),true);
    		myWriter.write("Append This!");
    		myWriter.close();
    So I have a text file try.txt and I have some text in it.
    When I run this code, the text existing in try.txt is gone, and I only see Append This! in my file?

    I thought the constructor in FileOutputStream(File, boolean append) should have worked for appending to the end of what is existing.

    What am I overlooking? Any help?

    Thanks.

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,800
    Rep Power
    25

    Default Re: Why can't I append to text file with JAVA ?

    Read the API doc for the constructors of classes you are using.
    Which constructor is getting the "true"?

  3. #3
    fatabass is offline Senior Member
    Join Date
    Nov 2011
    Location
    Turkey
    Posts
    380
    Blog Entries
    24
    Rep Power
    4

    Default Re: Why can't I append to text file with JAVA ?

    FileOutputStream(String name, boolean append)

  4. #4
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    Eastern Florida
    Posts
    17,800
    Rep Power
    25

    Default Re: Why can't I append to text file with JAVA ?

    Does it work now?

  5. #5
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Why can't I append to text file with JAVA ?

    Quote Originally Posted by fatabass View Post
    FileOutputStream(String name, boolean append)
    You'd better look again, and count opening and closing parenthesis.

  6. #6
    fatabass is offline Senior Member
    Join Date
    Nov 2011
    Location
    Turkey
    Posts
    380
    Blog Entries
    24
    Rep Power
    4

    Default Re: Why can't I append to text file with JAVA ?

    Thanks, now I see.

  7. #7
    stchman's Avatar
    stchman is offline Member
    Join Date
    Apr 2011
    Location
    Saint Louis, Missouri
    Posts
    97
    Rep Power
    0

    Default Re: Why can't I append to text file with JAVA ?

    The BufferedWriter class with a FileWriter constructor allows for text file appending.
    If you aren't programming in Java, well that's just too bad.
    I'd rather be using Ubuntu.

Similar Threads

  1. Append to file
    By berkeleybross in forum CLDC and MIDP
    Replies: 9
    Last Post: 06-18-2010, 12:42 PM
  2. Replies: 13
    Last Post: 12-11-2009, 09:43 AM
  3. append variables to a text file
    By ddatta8 in forum New To Java
    Replies: 2
    Last Post: 01-02-2009, 11:17 AM
  4. java DOM: append text to node
    By newbieal in forum New To Java
    Replies: 2
    Last Post: 10-10-2008, 08:18 PM
  5. Replies: 1
    Last Post: 08-07-2007, 06:35 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
  •