栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

铂西学习日记---打印流

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

铂西学习日记---打印流

* 打印流--就是为了方便进行输出,打印流分为两类,分别是
* 1.字符打印流 --- printWriter
* 2.字节打印流 --- printStream
import java.io.*;

public class demo_io5_print {
    public static void main(String[] args) {
//        bytePrint();
        charPrint();
    }
    
    public static void bytePrint(){
        File file = new File("1.txt");
        try {
            //字节输出流
            OutputStream out = new FileOutputStream(file);
            //字节输出缓冲流--加缓存提高效率
            BufferedOutputStream bos = new BufferedOutputStream(out);
            //字节输出打印流--方便操作
            PrintStream ps = new PrintStream(bos);
            ps.println("你好啊");
            //依然会关闭以上的流
            ps.close();

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

    public static void charPrint(){
        File file = new File("1.txt");
        try {
            //字符输出流
            Writer writer = new FileWriter(file);
            //字符输出缓冲流--加缓存提高效率
            BufferedWriter bw = new BufferedWriter(writer);
            //字符输出打印流--方便操作
            PrintWriter ps = new PrintWriter(bw);
            ps.println("你好啊呵");
            //依然会关闭以上的流
            ps.close();

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

 

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/720607.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号