system.out输出到文件上

  1. public class SayInFile {   
  2.     public SayInFile(){   
  3.         try {   
  4.             //文件生成路径   
  5.             PrintStream ps=new PrintStream("D:\role.txt");   
  6.             System.setOut(ps);   
  7.         } catch (FileNotFoundException e) {   
  8.             e.printStackTrace();   
  9.         }   
  10.     }   
  11.     public static void main(String[] args) {   
  12.         System.out.println("我在文件里了!");   
  13.     }   
原文地址:https://www.cnblogs.com/yangqimo/p/8269410.html