java-缓冲流

 

 

 

 

public class Demo6 {
    public static void main(String[] args) throws IOException {
        FileOutputStream fos = new FileOutputStream("C:\\Users\\quan\\Desktop\\练习\\src\\code\\haotusay.txt");
        BufferedOutputStream bos = new BufferedOutputStream(fos);
        bos.write("写入缓冲池".getBytes());
        bos.flush();
        bos.close();
    }
}

 

BufferInputStream

 

 

public class Demo6 {
    public static void main(String[] args) throws IOException {
        FileInputStream fos = new FileInputStream("C:\\Users\\quan\\Desktop\\练习\\src\\code\\haotusay.txt");
        BufferedInputStream bis = new BufferedInputStream(fos);
        int len =0 ;
        while ((len = bis.read()) != -1){
            System.out.println(len);
        }
        bis.close();//只需要关闭缓冲流,字节流会自动的随之关闭
    }
}

或者使用数组保存

 

 

 

posted @ 2020-06-19 22:49  小丑quan  阅读(149)  评论(0)    收藏  举报