打印字节流和字符流

 打印字节流和字符流 

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/ printWriter
    public 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();
        }
    }
}

打印字节流和字符流_第1张图片

打印字节流和字符流_第2张图片

你可能感兴趣的:(python,开发语言)