import com.sun.xml.internal.ws.policy.privateutil.PolicyUtils;

import java.io.*;

public class Test {
    public static void main(String[] args) {
//        Echo.test();
//        ChangeSystemOut.test();
        Redirecting.test();
    }
}

class Echo {
    public static void test() {
        BufferedReader stdin = new BufferedReader(
                new InputStreamReader(System.in));

        try{
            String s;
            while ((s = stdin.readLine()) != null&&s.length()!=0) {
                System.out.println(s);
            }
        } catch (IOException e) {
            //e.printStackTrace();
            throw new RuntimeException(e);
        }

    }
}

class ChangeSystemOut {
    public static void test() {
        PrintWriter out = new PrintWriter(System.out,true);
        out.println("Hello, world");
//        out.close();
    }
}

class Redirecting{
    public static void test() {
        try{
            PrintStream console = System.out;

            //创建输入流,用于重定向输入
            BufferedInputStream in = new BufferedInputStream(
                    new FileInputStream("./src/Test.java"));

            //创建输出流,用于重定向输出
            PrintStream out = new PrintStream(
                    new FileOutputStream("./src/out"));

            System.setIn(in);
            System.setOut(out);
            System.setErr(out);

            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

            try{
                String str;
                while ((str = br.readLine()) != null) {
                    System.out.println(str);
                }
            }finally {
                br.close();
                out.close();
            }
            System.setOut(console);

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e){
            e.printStackTrace();
        }

    }
}

最新文章

  1. 《疯狂Java讲义》(四)---- 面向对象&基于对象
  2. HTML基础(2)
  3. Reprot中的五个Trigger说明
  4. 机器人与机器人仿真技术(zz)
  5. 专访CEO何朝曦:深信服高速成长的秘诀
  6. ssh environment variable
  7. JS-运动基础(一)
  8. cocos2d-x-2.2.6创建工程
  9. C#分布式事务解决方案-TransactionScope
  10. redis伪集群脚本
  11. Javascript高级编程学习笔记(27)—— BOM(1)window对象1
  12. V-rep学习笔记:切削
  13. 我们为什么要学习 Spring Boot
  14. Django的基本开发环境配置和MTV模型
  15. BATJ面试必会之Java IO 篇
  16. vuex的简单使用
  17. UVA-673 Parentheses Balance(栈)
  18. 679. 24 Game
  19. uwp获取版本信息win10 VersionInfo
  20. Xpath提取一个标签里的所有文本

热门文章

  1. GIS基础软件及操作(七)
  2. VS2015设置VS2017的“快速操作”快捷键Alt+Enter
  3. Java8 的一些新特性总结
  4. ThinkPHP 提供Auth 权限管理、支付宝、微信支付、阿里oss、友盟推送、融云即时通讯、云通讯短信、Email、Excel、PDF 等等
  5. mstsc也要使用/admin参数
  6. HTTPS上线过程说明(阿里云提供免费证书)
  7. “真正的工作不是说的天花乱坠”,Torvalds 说, “而是在于细节”(Torvalds 认为成功的项目都是99%的汗水和1%的创新)
  8. delphi 在多线程中使用 CreateOleObject 导致失败(一定要使用CoInitialize和CoUninitialize,举例查询WMI)
  9. jquery选择器集锦
  10. 【Linux】Linux 环境下splite以及一些正则使用