BufferedInputStream(InputStream in, int size)
BufferedInputStream就是为了创建个指定缓冲区大小的 BufferedInputStream 并保存其参数
前面一个是指InputStream in输入流你应该清楚,后面的 size 值的是缓冲区大小的,创建的是一个长度为 size 的内部缓冲区数组,你这里的2*SIZE就是指两倍数组长度,建议你去看看API
BufferedInputStream 本身就是缓冲流,不要求建数组
FileInputStream 需要,把数据放到个数组里起到缓冲流效果
我贴一个自己些的代码,复制一首歌的操作,你对比下,变量名随便起的,不太规范
///////////////////////////////////////////////////////////////
File aFile=new File("C:\\Users\\Administrator\\Desktop\\a.mp3");
File bFile=new File("C:\\Users\\Administrator\\Desktop\\c.txt");
BufferedInputStream aa=new BufferedInputStream(new FileInputStream(aFile));
BufferedOutputStream bb=new BufferedOutputStream(new FileOutputStream(bFile));
int a= aa.read();
while ( a!=-1) {
bb.write(a);
a=aa.read();
}
aa.close();
bb.close();
//////////////////////
File aFile=new File("C:\\Users\\Administrator\\Desktop\\a.mp3");
File bFile=new File("C:\\Users\\Administrator\\Desktop\\aaa.mp3");
FileInputStream aFileInputStream=new FileInputStream(aFile);
FileOutputStream bFileOutputStream=new FileOutputStream(bFile);
byte[]a=new byte[100];
while (aFileInputStream.read(a)!=-1) {
bFileOutputStream.write(a);
}
aFileInputStream.close();