Write problem - lossing the original data

Posted by John on Stack Overflow See other posts from Stack Overflow or by John
Published on 2009-08-12T15:30:12Z Indexed on 2010/04/11 12:23 UTC
Read the original article Hit count: 258

Filed under:
|
|

Every time I write to the text file I will lose the original data, how can I read the file and enter the data in the empty line or the next line which is empty?

public void writeToFile()
{   

    try
    {
        output = new Formatter(myFile);
    }
    catch(SecurityException securityException)
    {
        System.err.println("Error creating file");
        System.exit(1);
    }
    catch(FileNotFoundException fileNotFoundException)
    {
        System.err.println("Error creating file");
        System.exit(1);
    }

    Scanner scanner = new Scanner (System.in);

    String number = "";
    String name = "";

    System.out.println("Please enter number:");
    number = scanner.next();

    System.out.println("Please enter name:");
    name = scanner.next();

    output.format("%s,%s \r\n",  number, name);
    output.close();

}

© Stack Overflow or respective owner

Related posts about java

Related posts about file-io