打印流:PrintStream
1、示例代码如下:
package com.jh.www;
import java.io.FileDescriptor;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintStream;
public class Test2 {
//打印流
public static void main(String[] args) throws IOException {
//输出到客户端;
PrintStream ps = System.out;
ps.println("打印流");
ps.println(true);
//输出到文件;
ps = new PrintStream(new FileOutputStream("aaa.txt"),true);
ps.println("打印流");
ps.println(true);
//重定向输出端;
System.setOut(ps);
ps.println("change");//change已存在文本中;
//重定向到客户端
ps = new PrintStream(new FileOutputStream(FileDescriptor.out),true);
ps.println("i am backing");
ps.close();
}
}