更新时间:2023-12-03 13:11:34
您可以通过扫描文件找到最后一行的开头,然后使用FileChannel.truncate$c$ c>
或 RandomAccessFile.setLength
。
I have a .txt
file, which I want to process in Java. I want to delete its last line.
I need ideas on how to achieve this without having to copy the entire content into another file and ignoring the last line. Any suggestions?
You could find the beginning of the last line by scanning the file and then truncate it using FileChannel.truncate
or RandomAccessFile.setLength
.