我有一个文本文件,其中包含多个条目,例如:
hello
there
my
name
is
JoeBloggs
如何按降序读取最后五个条目,即从JoeBloggs - there开始。
我目前只有读取最后一行的代码:
public class TestLastLineRead {
public static void main(String[] args) throws Exception {
FileInputStream in = new FileInputStream(file.txt);
BufferedReader br = new BufferedReader(new InputStreamReader(in));
String strLine = null, tmp;
while ((tmp = br.readLine()) != null) {
strLine = tmp;
}
String lastLine = strLine;
System.out.println(lastLine);
in.close();
}
}