Java使用缓冲流完成文件复制操作
import ;
import ;
import ;
import ;
import ;
import ;
/**
* 缓冲流:缓冲流是以对高级流
*
*
* 缓冲字节输入输出流是用来加快读写效率的
*
* 使用缓冲流完成复制操作
* @author asus
*
*/
public class CopyDemo2 {
public static void main(String[] args) throws IOException {
/**
* 使用文件输入流读取原文件,使用文件输出流往文件里写。
* 使用块读写形式
*
*/
FileInputStream fis=new FileInputStream("music.mp3");
BufferedInputStream bis=new BufferedInputStream(fis);
FileOutputStream fos=new FileOutputStream("music_cp.mp3");
BufferedOutputStream bos=new BufferedOutputStream(fos);
//byte[] data=new byte[1024*10];
int len=-1;
/**
* 使用了缓冲流读写时,我们就不在需要关注必须用块读写加快效率了
* 因为缓冲流内部维护了一个字节数组,最终会将我们的读写操作转换为
* 块读写加快读写效率的
*/
while((len=())!=-1){
(len);
}
("复制完毕");
();
();
}
}