字节缓冲流
代码实现:
package cn.itsource.test; 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; /** * @author * 字节缓冲 * */ public class ByteCopy { public static void main(String[] args) { // copy(new File("D:\\works\\day0108\\src\\cn\\itsource\\test\\_01tTest.java"), new File("D:\\123.txt")); } public static void copy(File file1,File file2) { try( //创建字节缓冲输入流 BufferedInputStream bi = new BufferedInputStream(new FileInputStream(file1)); //创建字节缓冲输出流 BufferedOutputStream bd = new BufferedOutputStream(new FileOutputStream(file2)); ) { if (bi==null || bd ==null) { throw new NullPointerException("不可为空!"); } //记录读取个数 int num; // StringBuilder s = new StringBuilder(); //创建字节数组 byte[] b = new byte[1024]; while ((num = bi.read(b))>0) { //输出到指定位置 bd.write(b, 0, num); } } catch (FileNotFoundException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } }