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

}

相关文章:

  • 2022-12-23
  • 2021-05-25
  • 2021-06-18
  • 2021-11-29
  • 2021-11-21
  • 2021-07-10
  • 2021-08-04
  • 2021-09-19
猜你喜欢
  • 2021-08-14
  • 2021-06-20
  • 2021-05-16
  • 2021-05-19
  • 2022-12-23
  • 2021-09-19
  • 2022-12-23
相关资源
相似解决方案