Java基础IO类之打印流

package IODemo;

import java.io.*;
/*
打印流 : 很方便的进行输出
字节打印流
    增强输出功能

字符打印流
 */
public class PrintStreamDemo {



    private  static  void charPrint(){
        File file = new File("d:\\test\\t.txt");
        try {
            Writer w = new FileWriter(file,true);
            BufferedWriter br = new BufferedWriter(w);
            PrintWriter ps = new PrintWriter(br);
            ps.println("嗨~");
            ps.close();

        } catch (IOException e) {
            e.printStackTrace();
        }

    }

    private static void bytePrint(){
        File file = new File("d:\\test\\t.txt");
        try {
            OutputStream out = new FileOutputStream(file,true);
            BufferedOutputStream bos = new BufferedOutputStream(out);
            PrintStream ps  =new PrintStream(bos);
            ps.println("好好学习天天向上");
            ps.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }

    }


    public static void main(String[] args) {

  //  bytePrint();
        charPrint();
    }
}

如上代码

posted @ 2019-12-03 22:16  Mr.落魄书生  阅读(33)  评论(0编辑  收藏