How to append to a text file

Discussion in 'Java' started by Dilantha Seneviratne, Jan 5, 2004.

  1. Hi
    Could somone advise me on how I could append lines to a text file.

    thanks
     
    Dilantha Seneviratne, Jan 5, 2004
    #1
    1. Advertising

  2. Dilantha Seneviratne schrieb:
    > Hi
    > Could somone advise me on how I could append lines to a text file.
    >
    > thanks
    >

    It's all in the docs:

    <http://java.sun.com/j2se/1.4.2/docs/api/java/io/FileWriter.html#FileWriter(java.lang.String,%20boolean)>
     
    Thomas Kellerer, Jan 5, 2004
    #2
    1. Advertising

  3. thanx

    Thomas Kellerer wrote:

    > Dilantha Seneviratne schrieb:
    > > Hi
    > > Could somone advise me on how I could append lines to a text file.
    > >
    > > thanks
    > >

    > It's all in the docs:
    >
    > <http://java.sun.com/j2se/1.4.2/docs/api/java/io/FileWriter.html#FileWriter(java.lang.String,%20boolean)>
     
    Dilantha Seneviratne, Jan 5, 2004
    #3
  4. Dilantha Seneviratne wrote:

    > Hi
    > Could somone advise me on how I could append lines to a text file.


    The relevant IO classes have constructors that allow you to do that.
     
    Michael Borgwardt, Jan 5, 2004
    #4
  5. Dilantha Seneviratne

    Chris Gokey Guest

    So, it would be something like this:
    String fileName = "file.txt";
    PrintWriter pw = new PrintWriter(new FileWriter(fileName,true));
    pw.println("Adding a line...");
    pw.close();

    Chris

    Thomas Kellerer wrote:

    > Dilantha Seneviratne schrieb:
    >> Hi
    >> Could somone advise me on how I could append lines to a text file.
    >>
    >> thanks
    >>

    > It's all in the docs:
    >
    > <http://java.sun.com/j2se/1.4.2/docs/api/java/io

    FileWriter.html#FileWriter(java.lang.String,%20boolean)>

    --
     
    Chris Gokey, Jan 5, 2004
    #5
  6. Dilantha Seneviratne

    Roedy Green Guest

    On Mon, 05 Jan 2004 14:46:26 GMT, Dilantha Seneviratne
    <> wrote or quoted :

    > Could somone advise me on how I could append lines to a text file.


    see http://mindprod.com/fileio.html

    --
    Canadian Mind Products, Roedy Green.
    Coaching, problem solving, economical contract programming.
    See http://mindprod.com/jgloss/jgloss.html for The Java Glossary.
     
    Roedy Green, Jan 5, 2004
    #6
  7. Dilantha Seneviratne

    Virgil Green Guest

    "Dilantha Seneviratne" <> wrote in message
    news:...
    > Hi
    > Could somone advise me on how I could append lines to a text file.
    >
    > thanks
    >

    http://www.textpad.com
     
    Virgil Green, Jan 6, 2004
    #7
  8. Andrew Thompson, Jan 7, 2004
    #8
  9. Dilantha Seneviratne

    Virgil Green Guest

    "Andrew Thompson" <> wrote in message
    news:XiNKb.81342$...
    > "Virgil Green" <> wrote in message
    > news:ZeEKb.151$...
    > |
    > | "Dilantha Seneviratne" <> wrote
    > in message
    > | news:...
    > | > Hi
    > | > Could somone advise me on how I could append lines to a
    > text file.
    > | >
    > | > thanks
    > | >
    > | http://www.textpad.com
    >
    > Tut, tut Virgil. You forgot to mention..
    > 'Type some text in the editor - and save'... :)
    >


    There was no mention of persistence.

    - Virgil
     
    Virgil Green, Jan 8, 2004
    #9
  10. Dilantha Seneviratne

    Lans Redmond Guest

    Look at the class RandomAccessFile



    "Virgil Green" <> wrote in message
    news:0whLb.5539$...
    >
    > "Andrew Thompson" <> wrote in message
    > news:XiNKb.81342$...
    > > "Virgil Green" <> wrote in message
    > > news:ZeEKb.151$...
    > > |
    > > | "Dilantha Seneviratne" <> wrote
    > > in message
    > > | news:...
    > > | > Hi
    > > | > Could somone advise me on how I could append lines to a
    > > text file.
    > > | >
    > > | > thanks
    > > | >
    > > | http://www.textpad.com
    > >
    > > Tut, tut Virgil. You forgot to mention..
    > > 'Type some text in the editor - and save'... :)
    > >

    >
    > There was no mention of persistence.
    >
    > - Virgil
    >
    >
     
    Lans Redmond, Jan 9, 2004
    #10
  11. "Virgil Green" <> wrote in message
    news:0whLb.5539$...
    | "Andrew Thompson" <> wrote in message
    | news:XiNKb.81342$...
    .....
    | > | > Could somone advise me on how I could append lines to
    a
    | > text file.
    | > | >
    | > | > thanks
    | > | >
    | > | http://www.textpad.com
    | >
    | > Tut, tut Virgil. You forgot to mention..
    | > 'Type some text in the editor - and save'... :)
    | >
    |
    | There was no mention of persistence.

    Good point! I missed that..
     
    Andrew Thompson, Jan 9, 2004
    #11
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Rach
    Replies:
    3
    Views:
    13,634
    Malcolm Dew-Jones
    Aug 24, 2004
  2. gukn9700

    Can I append text to a file?

    gukn9700, Jul 16, 2003, in forum: C++
    Replies:
    2
    Views:
    5,711
    gukn9700
    Jul 17, 2003
  3. sm
    Replies:
    2
    Views:
    561
    Rolf Magnus
    Apr 29, 2005
  4. HYRY
    Replies:
    10
    Views:
    625
    Bruno Desthuilliers
    Sep 26, 2007
  5. sylvaticus
    Replies:
    3
    Views:
    354
    sylvaticus
    Oct 16, 2007
Loading...

Share This Page