相比于字节流更快
package com.hncu.myfiledemo;
import java.io.*;
public class Demo6 {
//缓冲流字节实现文件复制
public static void main(String[] args) throws IOException {
BufferedInputStream bis = new BufferedInputStream(new FileInputStream("F:\\picture\\picture.jpg"));
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream("myfile\\picture.jpg"));
int b;
while ((b = bis.read()) != -1){
bos.write(b);
}
bis.close();
bos.close();
}
}
package com.hncu.myfiledemo;
import java.io.*;
public class Demo7 {
//缓冲流数组实现复制文件
public static void main(String[] args) throws IOException {
//缓冲流底层有一个默认长度文8192的数组
BufferedInputStream bis = new BufferedInputStream(new FileInputStream("F:\\picture\\picture.jpg"));
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream("myfile\\picture.jpg"));
//数组内容传给缓冲流数组
byte[] bytes = new byte[1024];
int len;//记录缓冲流数组长度
while ((len = bis.read(bytes))!=-1){
bos.write(bytes,0,len);
}
bis.close();
bos.close();
}
}