I'm using Java FileWriter to take some data from one file, that will do undergo some transformation and be put in to an output file. I want the output file to be at least cleared, if not deleted after each time I run my app so my question is just how would I achieve this?
This is what I've got so far:
try {
file = new File(filepath);
fileWriter = new FileWriter(file, true);
fileWriter.write(data.toJSONString() + "\n");
fileWriter.flush();
fileWriter.close();
}
catch (IOException e) {
e.printStackTrace();
}
System.out.print(data + "\n");
System.out.print(o + "\n");
}
file.createNewFile();