实例
import java.io.BufferedOutputStream;import java.io.File;import java.io.FileOutputStream;import java.io.IOException;/** * 字节输出缓冲流 * @author Administrator * */public class BufferOutputStreamStudy { public static void main(String[] args) { // TODO Auto-generated method stub //定义文件对象 String path = "D:\\movie\\japan\\dj\\cxk.txt"; File file = new File(path); BufferedOutputStream bos = null; FileOutputStream fos = null; try { if(!file.exists()) { file.createNewFile(); } //实例化流 fos = new FileOutputStream(file); bos = new BufferedOutputStream(fos); //向文件写入内容 String str = "它不是拍电影的,它是个运动员!!!!!!!"; byte[] data = str.getBytes(); //写 bos.write(data); //刷新(清空)缓冲流-->低级流 bos.flush(); }catch (Exception e) { // TODO: handle exception e.printStackTrace(); }finally { //关闭流 try { bos.close(); fos.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }}