打印流
1、可以自动刷新,需要将new PrintStream()第二个参数设置为true;
2、可以设置重定向输出端将内容输出到指定文件。
3、将输出端重定向为控制台。
public static void main(String[] args) throws FileNotFoundException {
//System.out
PrintStream ps = System.out;
ps.println("cbdhs");
ps = new PrintStream(new BufferedOutputStream(new FileOutputStream("print.txt")),true); //第二个参数为真则自动刷新
//ps.flush();
//重定向输出端
System.setOut(ps);
System.out.print("ghs");
//重定向为控制台
System.setOut(new PrintStream(new BufferedOutputStream(new FileOutputStream(FileDescriptor.out)),true));
}