首页 > 代码库 > JAVA IO ( 两种打印流 )

JAVA IO ( 两种打印流 )

<!--字符打印流-->

public class CharDemo {
    public static void main(String[] args) throws Exception {
        // 创建字符打印流
        PrintWriter p = new PrintWriter(new FileWriter(new File("src/打印流_输出流/text.txt"), true));
        p.print("黄伟强");
        p.println();
        p.print(345);
        p.close();
    }
}

<!--字节打印流-->

public class ByteDemo {
    public static void main(String[] args) throws Exception {
        // 创建字节打印流
        PrintStream p = new PrintStream(new FileOutputStream(new File("src/打印流_输出流/text.txt"), true));
        p.print("黄");
        p.println();
        p.print(123);
        p.close();
    }
}

 

JAVA IO ( 两种打印流 )