how to delete the content of text file without deleting itself
I don't believe you even have to write an empty string to the file.
PrintWriter pw = new PrintWriter("filepath.txt");
pw.close();
Just print an empty string into the file:
PrintWriter writer = new PrintWriter(file);
writer.print("");
writer.close();