System.out.println()输出到文件里

System.out.println(); 
程序运行他会输出在哪里:  控制台吧。 

那如果我不想把他输出到控制台,想把他输出到一个文件里面去怎么做呢? 
看下面代码你就明白了。 
  1. public static void main(String[] args) throws Exception {  
  2.     String str = "abcd";  
  3.     PrintStream out = new PrintStream("f:/test.txt");  
  4.     System.setOut(out);  
  5.     System.out.println(str);  
  6. }

猜你喜欢

转载自blog.csdn.net/qiuzhongweiwei/article/details/80328841
今日推荐