Im trying to write a text to file, but it overwrites whats inside, can somebody explain how to check if the text exists and then put a new line and write? Here is the code I am working with:
try
{
    if (!file.exists())
    {
        file.createNewFile();
    }
    FileWriter fw =
        new FileWriter(file.getAbsoluteFile());
    BufferedWriter bw = new BufferedWriter(fw);
    bw.newLine();
    bw.write(petName);
    bw.close();
    System.out.println("Done!");
}
catch (IOException exc)
{
    System.out.println(exc);
}
Thank you for any kind of help.
 
     
     
    