高效字节流bufferedinputstream和bufferedoutputstream

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/aaa958099161/article/details/78288530
public class MyBuffer {

public static void main(String[] args) throws IOException{

//在这里定义,后面finally关闭

BufferedInputStream bufferedInputStream=null;
BufferedOutputStream bufferedOutputStream=null;

try{

//其实就是装饰着模式,内部调用的还是fileinputstream和fileoutputstream

bufferedInputStream=new BufferedInputStream(new FileInputStream("IO.txt"));
bufferedOutputStream=new BufferedOutputStream(new FileOutputStream("buffer.txt"));

int len=0;

//写入,这里是读取很多字节,然后一起写入

while((len=bufferedInputStream.read())!=-1){
bufferedOutputStream.write(len);
}}catch(Exception e){

e.printStackTrace();
}finally{
if(bufferedInputStream!=null){
bufferedInputStream.close();}
if(bufferedInputStream!=null){
bufferedOutputStream.close();
}
}

}
阅读更多
博主设置当前文章不允许评论。

没有更多推荐了,返回首页