打印字节流和字符流
printStream/ printWriter的构造器和方法都是一样的
package printfile;import java.io.FileOutputStream;
import java.io.OutputStream;
import java.io.PrintStream;
import java.io.PrintWriter;
import java.nio.charset.Charset;public class PrintTest {//目标:掌握打印流 printStream/ printWriterpublic static void main(String[] args) {try (// 创建打印管道//打印字节// PrintStream ps=new PrintStream("src/zFIle/StreamPrint.txt", ("GBK"));// PrintStream ps=new PrintStream("src/zFIle/StreamPrint.txt", Charset.forName("GBK"));//PrintStream ps=new PrintStream("src/zFIle/StreamPrint.txt", Charset.forName("UTF-8"));//打印字符输出//高级流不能追加数据// PrintWriter ps=new PrintWriter("src/zFIle/StreamPrint.txt", Charset.forName("GBK"));PrintWriter ps= new PrintWriter(new FileOutputStream("src/zFIle/StreamPrint.txt", true));){ps.print("97" );ps.print("'a'" );ps.print("我爱你中国" );ps.print(true );ps.println(67.6 );ps.println("love" );//写字节数据ps.write(97);} catch (Exception e) {e.printStackTrace();}}
}