2013-08-06 31 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'));