【问题标题】:BufferedReader not seeing end-of-file on StdIn when run under Eclipse在 Eclipse 下运行时,BufferedReader 在 StdIn 上看不到文件结尾
【发布时间】:2021-02-26 18:10:04
【问题描述】:

我正在阅读标准输入:

    public static void main(String[] args) {
        try {
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            for (;;) {
                var line = br.readLine();
                if (line == null) break;
                System.out.println(line);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        
        System.err.println("Done.");
    }

如果我在终端中使用它:

java TheClass </path/to/file

...它起作用了:程序运行完成。

但是在 Eclipse 下,如果我将相同的文件设置为标准输入(Run Configurations>Common>Standard Input and output),程序会读取该文件,但它会在最后一行之后挂起,直到我输入控制台窗口中的 Ctrl-D(然后正常终止)。

同样在 Eclipse 下,如果我直接使用文件(FileInputStream),文件被读到最后,程序立即终止。

是我遗漏了什么还是 Eclipse 问题?

在带有 openjdk 11 的 Linux 上使用 Eclipse 2020-06。

【问题讨论】:

    标签: java eclipse stdin


    【解决方案1】:
    猜你喜欢
    • 1970-01-01
    • 2013-07-14
    • 2011-09-24
    • 2017-05-21
    • 2021-11-20
    • 2011-11-24
    • 2017-04-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多