询问InputStream“System.in”

时间:2013-08-06 14:23:36

标签: java io nio bufferedinputstream

我想实现以下目标:

BufferedInputStream is = new BufferedInputStream(System.in);
        int c = 0;
        while((c=is.read())!=-1)
        Files.copy(is, path3, StandardCopyOption.REPLACE_EXISTING);

Hoewver卡在等待System.in永远.. 对此有何解决方法?

提前致谢。

1 个答案:

答案 0 :(得分:1)

如果您试图停止阅读新行或回车或流结束,您可以尝试 -

do {

    try {

        c = is.read();

        // Do something

    } catch (IOException e) {

        e.printStackTrace();

    }

} while ((c != -1) & (c != '\n') & (c != '\r'));
相关问题