使用Java读取文本文件的最后一行



我对Java相当陌生,我想问如何使用Java获得文本文件的最后一行?例如,文本文件的内容类似于:

001, abc, abc@yahoo.com, 123456,

002, xxx, xxx@gmail.com, xxx,

我想要得到的是用户的userID(例如:001)。我已经知道如何正常地从文本文件中读取,但我需要的是文本文件中的最后一行,以便我可以为用户提供递增的id。

try (ReversedLinesFileReader reader = new ReversedLinesFileReader(new File("path/to/file.txt"), StandardCharsets.UTF_8)) {
System.out.println("Last line is: " + reader.readLine());
} catch (IOException e) {
// ignore for now
}

它应该工作完美

最新更新