Deleting the last line of a file with Java

后端 未结 2 900
粉色の甜心
粉色の甜心 2020-12-18 00:58

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 enti

2条回答
  •  失恋的感觉
    2020-12-18 01:21

    You could find the beginning of the last line by scanning the file and then truncate it using FileChannel.truncate or RandomAccessFile.setLength.

提交回复
热议问题