而JAVA中的EOF? [英] while EOF in JAVA?

查看:421
本文介绍了而JAVA中的EOF?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在一些论坛的答案之后,我正在使用这个:

Following to some forums answers I'm using this:

    while (fileReader.nextLine() != null) {
        String line = fileReader.nextLine();
        System.out.println(line);
    }  

...但它最终抛出异常
(线程main中的异常java.util.NoSuchElementException:找不到行)

... but it throws exception at the end anyway (Exception in thread "main" java.util.NoSuchElementException: No line found)

推荐答案

你应该使用 while(fileReader.hasNextLine())

这篇关于而JAVA中的EOF?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆