//通过定义数组读取明显比一个一个快,有个数组来做缓冲区很管用
//java想到了这个问题,就提供了 带缓冲区的字节类
//缓冲类--高效类
--它只是一个缓冲区,真正的操作还是要靠流来进行,只是用它做个容器
BufferedOutputStream:
代码简单实现:
try{
BufferedOutputStream buo = new BufferedOutputStream(new FileOutputStream("D:/a.txt"));
buo.write("阿斯顿".getBytes());
buo.close();
}catch (Exception e) {
throw new RuntimeException(e);
}
BufferedInputStream:
try {
BufferedInputStream buff = new BufferedInputStream(new FileInputStream("D:/a.txt"));
byte [] b = new byte[1024];
int index =0;
while((index=buff.read(b))!=-1){
System.out.println(new String(b,0,index));
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
缓冲流速度很快。以前的知识 差不多想起来了