FileReader fileReader = null;
try {
fileReader = new FileReader(file);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
Scanner sc = new Scanner(fileReader);
String line = null;
while((sc.hasNextLine()&&(line=sc.nextLine())!=null)){
if(!sc.hasNextLine()){
System.out.println(line);
}
}
sc.close();
java读取文件最后一行的方法
最新推荐文章于 2023-08-07 18:20:38 发布
本文提供了一个使用Java进行文件读取的简单示例。通过FileReader和Scanner类实现了对指定文件逐行读取的功能,并在读取完成后关闭资源。适用于初学者了解基本的文件操作。

433

被折叠的 条评论
为什么被折叠?



