我的家園

          我的家園

          JAVA I/O重定向

          Posted on 2012-04-15 16:37 zljpp 閱讀(1286) 評論(0)  編輯  收藏

           
          import java.io.BufferedInputStream;
          import java.io.BufferedOutputStream;
          import java.io.BufferedReader;
          import java.io.File;
          import java.io.FileInputStream;
          import java.io.FileOutputStream;
          import java.io.IOException;
          import java.io.InputStreamReader;
          import java.io.PrintStream;

          public class Redirecting {

              public static void main(String[] args) throws IOException {
                  PrintStream console = System.out;
                  BufferedInputStream in = new BufferedInputStream(new FileInputStream(new File("src/com/io/Redirecting.java").getAbsolutePath()));
                  PrintStream out = new PrintStream(new BufferedOutputStream(new FileOutputStream(new File("src/com/io/").getAbsolutePath() +"/test.out")),true);//第二個參數很重要
                  System.setIn(in);
                  System.setOut(out);
                  System.setErr(out);
                  BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
                  String s;
                  while((s = reader.readLine())!= null){
                      System.out.println(s);
                      out.close();
                      System.setOut(console);
                  }
              }
          }



          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 迁西县| 马公市| 高密市| 漯河市| 鹤岗市| 湘潭县| 晋州市| 嘉荫县| 天门市| 宣威市| 宜良县| 博野县| 综艺| 岢岚县| 临猗县| 连云港市| 临高县| 钟祥市| 方正县| 专栏| 桐梓县| 应城市| 木兰县| 郁南县| 长岭县| 江达县| 新余市| 台江县| 宁化县| 察隅县| 临安市| 始兴县| 祥云县| 漠河县| 抚州市| 陆丰市| 邵东县| 荆门市| 潼南县| 衡山县| 贵定县|