如何确定何时到达文件结尾? [英] How to determine when end of file has been reached?
本文介绍了如何确定何时到达文件结尾?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要帮助确定何时发生文件结束。如何在Java中确定它?
FileInputStream istream = new FileInputStream(\+ filename +\ );
扫描仪输入=新扫描仪(istream);
while(EOF!= true)
{
....
}
感谢!
解决方案您可以使用
hasNextLine() code $:
$ b $ pre $ code>扫描仪输入=新扫描仪(新文件(\+文件名+\ ));
while(input.hasNextLine())
{
String data = input.nextLine();
}
I am trying to read text from a text file. I need help figuring out when the end of file has occured. How can I determine this in Java?
FileInputStream istream = new FileInputStream("\""+filename+"\"");
Scanner input = new Scanner(istream);
while(EOF != true)
{
....
}
Thanks!
解决方案
You can check using hasNextLine()
:
Scanner input = new Scanner(new File("\""+filename+"\""));
while(input.hasNextLine())
{
String data = input.nextLine();
}
这篇关于如何确定何时到达文件结尾?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文