你是否经常用一些system.out.println();打印一些东西,你是否想把他们保存在文件当中,保留下来,不再受重启丢失之苦,那么你就按照下面的方法保存把。
- public static void main(String[] args) throws Exception {
- String str = "sout";
- PrintStream out = new PrintStream("c:/test.txt");
- System.setOut(out);
- System.out.println(str);
- }