Results 1 to 2 of 2
  1. #1
    Albert is offline Senior Member
    Join Date
    Jun 2007
    Rep Power

    Default Problem with storing and retrieving from a textfile

    I used these lines of code for getting data from text field and storing into a textfile.
    But this overwrites into same place, all i want to do is storing more than one data in a same file.

    Also I could not retrieve data from a text file using BufferedReader method.
    Java Code:
    BufferedWriter fileOut = new BufferedWriter(new FileWriter("filename.txt"));  //Create the Buffered Writer object to write to a file called filename.txt
     // Write to the file, using the text from our textfield
    fileOut.close(); // Close the output stream after all output is done.
    catch (IOException ioe)

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


    You'll probably want to use .append(char c) rather than .write()

    Writer (Java 2 Platform SE 5.0)
    BufferedWriter (Java 2 Platform SE 5.0)

    Another way (besides what Gox has written) is when you create the new FileWriter is to add a boolean of true for appending.

    Java Code:
    public class test
      public static void main (String args[]) throws IOException
        BufferedWriter stdout = new BufferedWriter(new FileWriter("file.txt", true));
    That will always append to the end when you do stdout.write("something");
    FileWriter (Java 2 Platform SE 5.0)

Similar Threads

  1. ECG plot in a textfile
    By samson in forum Java 2D
    Replies: 13
    Last Post: 01-28-2012, 05:02 PM
  2. Search TextFile
    By in forum Advanced Java
    Replies: 5
    Last Post: 04-11-2008, 12:03 PM
  3. storing and retrieving a file as such
    By anil_manu in forum Advanced Java
    Replies: 0
    Last Post: 03-11-2008, 02:27 PM
  4. reading textfile from java problem
    By saytri in forum New To Java
    Replies: 1
    Last Post: 01-17-2008, 03:13 AM
  5. Storing Data
    By Khorod in forum New To Java
    Replies: 1
    Last Post: 08-03-2007, 06:48 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