码迷,mamicode.com
首页 > 其他好文 > 详细

字节输出流OutputStream

时间:2019-08-16 18:25:21      阅读:77      评论:0      收藏:0      [点我收藏+]

标签:close   资源   str   img   提高   puts   byte   string   rgs   

1、OutputStream是输出字节流的超类。

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

public class FileOutputStreamDemo {
    public static void main(String[] args) throws IOException {
        File file = new File("E:\\IO流\\java\\1.txt");
        FileOutputStream f = new FileOutputStream(file, true);// 加true后可以实现续写功能
        String str = "\r\n" + "nihao";// 换行
        f.write(str.getBytes());
        f.write("你好".getBytes());
        f.write(8);
        f.close();//释放输出流的资源占用

    }
}

技术图片

2、缓冲区

write()方法所写的数据并不是直接写入到外设,而是先存放到缓冲区中,积累到一定程度再写到外设,这样可以提高系统效率。但有的时候缓冲区不满就需要写到外设上,需要调用flush()方法。

字节输出流OutputStream

标签:close   资源   str   img   提高   puts   byte   string   rgs   

原文地址:https://www.cnblogs.com/zhai1997/p/11365455.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!