zoukankan      html  css  js  c++  java
  • flush() 缓冲输出流的缓冲区问题

    package seday06;

    import java.io.BufferedOutputStream;
    import java.io.FileOutputStream;
    import java.io.IOException;

    /**
    * @author xingsir
    * 缓冲输出流的缓冲区问题
    */
    public class Bos_flushDemo {

    public static void main(String[] args) throws IOException {
    //文件流
    FileOutputStream fos=new FileOutputStream("test2.txt");
    //缓冲流
    BufferedOutputStream bos=new BufferedOutputStream(fos);

    String str= "我要~这个铁棒有何用,我有~这变化又如何";//字符串

    bos.write(str.getBytes());//将字符串转换为字节写入文件
    /*
    * flush方法是将缓冲区中已经缓存的数据一次性写出
    * 频繁的调用会降低写出效率,但是可以改变写出数据的及时性。
    */
    bos.flush();
    System.out.println("写出完毕");
    bos.close();
    }

    }

  • 相关阅读:
    junit单元测试
    方法引用
    方法引用表达式(1)
    Stream流的常用方法
    Stream流
    综合案例:文件上传
    tcp通信协议
    python 生成器与迭代器
    Python 序列化与反序列化
    python 文件操作
  • 原文地址:https://www.cnblogs.com/xingsir/p/12023083.html
Copyright © 2011-2022 走看看