可以改变输出语句的目的地(打印流的流向)

 1 package com.itheima.demo05.PrintStream;
 2 
 3 import java.io.FileNotFoundException;
 4 import java.io.PrintStream;
 5 
 6 /*
 7     可以改变输出语句的目的地(打印流的流向)
 8     输出语句,默认在控制台输出
 9     使用System.setOut方法改变输出语句的目的地改为参数中传递的打印流的目的地
10         static void setOut(PrintStream out)
11           重新分配“标准”输出流。
12  */
13 public class Demo02PrintStream {
14     public static void main(String[] args) throws FileNotFoundException {
15         System.out.println("我是在控制台输出");
16 
17         PrintStream ps = new PrintStream("10_IO\\目的地是打印流.txt");
18         System.setOut(ps);//把输出语句的目的地改变为打印流的目的地
19         System.out.println("我在打印流的目的地中输出");
20 
21         ps.close();
22     }
23 }

 

posted @ 2020-05-13 19:31  鑫淼  阅读(219)  评论(0)    收藏  举报