打印流
是一种处理流,方便打印各种数据。
import java.io.*;
public class PrintStreamTest {
public static void main(String[] args) throws FileNotFoundException {
PrintStream ps = System.out;
ps.print("Makka");
//打印到文件中,true表示开启自动刷新功能
ps = new PrintStream(new BufferedOutputStream(new FileOutputStream("dest.txt")),true);
ps.print("Makkakka");
ps.close();
//重定向输出端
System.setOut(ps);
System.out.println("hhh"); //输出到了文件中
//回控制台
System.setOut(new PrintStream(new BufferedOutputStream(new FileOutputStream(FileDescriptor.out)),true));
System.out.println("www");
System.out.println("lll");
}
}