2012-10-07 20 views

回答

1

您將處理System.in流並捕獲/處理源程序(本例中爲dir)提供的任何內容。

1

處理的System.inTest類,這裏是例子:

public class Test { 
    public static void main(String[] args) { 
     InputStream in = System.in; 
     try { 
      ByteArrayOutputStream bos = new ByteArrayOutputStream(); 
      int next = in.read(); 
      while (next > -1) { 
       bos.write(next); 
       next = in.read(); 
      } 
      bos.flush(); 
      byte[] bytes = bos.toByteArray(); 
      System.out.println("output:" + new String(bytes)); 
     } catch (IOException e) { 
      e.printStackTrace(); 
     } 
    } 
}