在Java中截断文件的最佳实践方法是什么?例如,这个虚拟函数,仅作为澄清意图的示例:
void readAndTruncate(File f, List<String> lines)
throws FileNotFoundException {
for (Scanner s = new Scanner(f); s.hasNextLine(); lines.add(s.nextLine())) {}
// truncate f here! how?
}
Run Code Online (Sandbox Code Playgroud)
由于文件充当占位符,因此无法删除该文件.