0

我想实现以下目标:

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

然而,它永远停留在等待 System.in 中。有什么解决方法吗?

提前致谢。

4

1 回答 1

1

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

do {

    try {

        c = is.read();

        // Do something

    } catch (IOException e) {

        e.printStackTrace();

    }

} while ((c != -1) & (c != '\n') & (c != '\r'));
于 2013-08-06T15:19:23.840 回答