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

如上代碼java

相關文章
相關標籤/搜索