2013-08-06 29 views
0

我想实现如下:询问的InputStream“System.in”

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

Hoewver它陷在等待System.in永远.. 什么解决办法是什么?

在此先感谢。

+0

它不能在构造块。你的意思是'is.read()'? –

+0

这是阻止试图从控制台读取..你键入任何输入? –

+0

你是否在控制台按'return'?在此之前,'System.in'看不到任何输入。 –

回答

1

如果你正在尝试停止读取新行或回车或流的末尾,你可以试戴

do { 

    try { 

     c = is.read(); 

     // Do something 

    } catch (IOException e) { 

     e.printStackTrace(); 

    } 

} while ((c != -1) & (c != '\n') & (c != '\r'));