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.     }   
posted @ 2018-01-11 17:11  one_person  阅读(273)  评论(0编辑  收藏  举报