I need to delete the contents of the file before writing additional information. I tried different ways, for example, when I delete the contents, but the file remains the same size, and when I start writing in it after the deletion, the empty hole looks like the size of the deletion before my new data is written.
Here is what I tried ...
BufferedWriter bw;
try {
bw = new BufferedWriter(new FileWriter(path));
bw.write("");
bw.close();
}
catch (IOException e) {
e.printStackTrace();
}
And I also tried this ...
File f = new File(file);
FileWriter fw;
try {
fw = new FileWriter(f,false);
fw.write("");
}
catch (IOException e) {
e.printStackTrace();
}
Can someone please help me with a solution to this problem.
source
share