zoukankan      html  css  js  c++  java
  • BufferedOutputStream缓冲流

    1.字节缓冲输出流

    /*
    使用步骤:
    1.创建FileOutputStream对象,构造方法中绑定要输出的目的地
    2.创建FileOutputStream对象,构造方法中传递FileOutputStream对象,提高FileOutputStream对象效率
    3.使用FileOutputStream对象中的方法write,把数据写到内部的缓冲区中
    4.使用FileOutputStream对象中的flush,把内部缓冲区的数据,刷新到文件中
    5.释放资源(会先调用flush方法刷新数据,4可省略)
    
    
    */
    
    import java.io.BufferedOutputStream;
    import java.io.FileNotFoundException;
    import java.io.FileOutputStream;
    import java.io.IOException;
    
    public class Demo01BufferedOutputStream {
        public static void main(String[] args) throws IOException {
            FileOutputStream fos=new FileOutputStream("F:\basic\untitled13\src\it\cast\day15\demo04\a.txt");
            BufferedOutputStream bos=new BufferedOutputStream(fos);
            bos.write("我把数据写入到内部缓冲区中".getBytes());
            bos.flush();
            bos.close();
        }
    }

    2.字节缓冲输入流

    //字节缓冲输入流
    
    import java.io.BufferedInputStream;
    import java.io.FileInputStream;
    import java.io.IOException;
    /*使用步骤:
    1.创建BufferedInputStream对象,构造方法中绑定要读取的数据源
    2.创建BufferedInputStream对象,构造方法中传递BufferedInputStream对象,提高读取效率
    3.BufferedInputStream对象read,读取文件
    4.释放资源*/
    public class Demo02BufferedInputStream {
        public static void main(String[] args) throws IOException {
            FileInputStream fis=new FileInputStream("F:\basic\untitled13\src\it\cast\day15\demo04\a.txt");
            BufferedInputStream bis=new BufferedInputStream(fis);
         /*   int len=0;
            while ((len=bis.read())!=-1){
                System.out.println(len);
            }*/
            byte[] bytes=new byte[1024];
            int len=0;
            while ((len=bis.read(bytes))!=-1){
                System.out.println(new String(bytes,0,len));
            }
            bis.close();
        }
    }
  • 相关阅读:
    GBDT(MART)
    C#中数组中Skip、Take和Concat的用法
    VUE中对获取到的数组进行排序
    el-date-picker只能选择今天
    Vue获取时间
    执行Add-Migration Initial报错
    Vue中使用for循环绑定值
    Element UI——日期时间选择器el-date-picker开始时间与结束时间约束解决方案
    el-date-picker日期组件
    缓存的问题
  • 原文地址:https://www.cnblogs.com/cy2268540857/p/13795720.html
Copyright © 2011-2022 走看看