how to delete the content of text file without deleting itself January 14, 2023 by Tarik Just print an empty string into the file: PrintWriter writer = new PrintWriter(file); writer.print(""); writer.close();