I try to build a simple android app that shows text on the screen and has a button. I created a log file at the onCreate() method and would like to append the new log line to the document upon the click on the button. I used the following code in both onCreate() and onButtonClick() events:
try{
    if(!file.exists()){
        System.out.println("We had to make a new file.");
        file.createNewFile();
    }
    FileWriter fileWriter = new FileWriter(file, true);
    String ts = new SimpleDateFormat("yyyy.MM.dd.HH.mm.ss").format(new Date());
    Log.d("LOGGER" , ts);
    BufferedWriter bufferedWriter = new BufferedWriter(fileWriter);
    bufferedWriter.write("******* " + ts.toString() +" ******* " + "\n");
    bufferedWriter.close();
    fileWriter.close();
    System.out.println("Done");
} catch(IOException e) {
    System.out.println("COULD NOT LOG!!");
}
The file is created and is filled with the data uppon onCreate(), the problem is that when I call onButtonClick() the new log line is not appended to the log file despite the fact I specified true in the FileWriter constructor: new FileWriter(file, true).
Could you point me, why my log is not appended with the new lines?
 
    