Java基础-重写System.out.println方法

PrintStream myStream = new PrintStream(System.out) {
    @Override
    public void println(String x) {
        super.println(System.currentTimeMillis() + ": " + x);
    }
};
System.setOut(myStream);
System.out.println("Hello World!");
-------------------------------------------------------------------------------
Output:
1420553422337: Hello World!

参考:http://stackoverflow.com/questions/27800326/hook-into-system-out-println-and-modify

posted @ 2016-12-25 12:51  EasonJim  阅读(3016)  评论(0编辑  收藏  举报