标准输入输出

 1 public class TestStream {
 2     
 3     /**
 4      * 标准输出,显示器(console)
 5      */
 6     @Test
 7     public void testSystemOut() throws Exception{
 8         System.setOut(new PrintStream(new FileOutputStream("d:/arch/a.txt")));
 9         System.out.println("helloworldxxxxxxxxxxxx");
10     }
11     
12     /**
13      * 标准输入(键盘)
14      */
15     @Test
16     public void testSystemIn() throws Exception{
17         InputStream in = System.in ;
18         BufferedReader br = new BufferedReader(new InputStreamReader(in));
19         String line = null ;
20         while((line = br.readLine()) != null){
21             if(line.equals("quit")){
22                 System.exit(-1);
23             }
24             System.out.println("hello : " + line);
25         }
26     }
27 }
28  

 

posted on 2017-04-29 16:13  艺海浮台  阅读(119)  评论(0)    收藏  举报