import java.io.FileNotFoundException; import java.io.PrintStream; public class Demo04PrintStream { public static void main(String[] args) throws FileNotFoundException { System.out.println("我在控制台输出"); PrintStream ps=new PrintStream("F:\basic\untitled13\src\it\cast\day15\demo06\print.txt"); System.setOut(ps);//重新分配标准输出流,改变输出语句的目的地改为参数传递的打印流的目的地 System.out.println("我在打印流的目的地输出"); ps.close(); } }