java读取文件的最后一行数据

Scanner sc=new Scanner(new FileReader("D:\\text.txt"));
String line=null;
while((sc.hasNextLine()&&(line=sc.nextLine())!=null)){
    if(!sc.hasNextLine())
    System.out.println(line);
}

猜你喜欢

转载自blog.csdn.net/zhaoraolin/article/details/80085230