java实现文件的复制(使用BufferedStream缓冲流实现)
1、
代码语言:javascript复制import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
/**
* java实现文件的复制(使用BufferedStream缓冲流实现)
* @author com
*
*/
public class BufferIOStream {
public static void main(String[] args) throws IOException {
File file1 = new File("D:/data/old.mp3");
File file2 = new File("D:/data/new.mp3");
FileInputStream fis = new FileInputStream(file1);
FileOutputStream fos = new FileOutputStream(file2);
BufferedInputStream bufferedin = new BufferedInputStream(fis);
BufferedOutputStream bufferedout = new BufferedOutputStream(fos);
int temp = 0;
while((temp=bufferedin.read()) != -1) {
bufferedout.write(temp);
}
}
}
2、实现效果
3、总结
使用BufferedInputStream和BufferedOutputStream是系统自带的缓冲流,速度比字节的逐个读取效率要快很多。