拷贝音频、视频、word等二进制文件的实现方法:
演示使用BufferedOutputStream 和 BufferedInputStream 使用
使用他们,可以完成二进制文件
思考:字节流可以操作二进制文件,可以操作文本文件吗?True

public class BufferedInputStreamCopy_ {public static void main(String[] args) throws IOException {String srcPath = "E:\\demo.java";String destPath = "E:\\Copy.java";byte[] buf = new byte[1024];int bufLen = 0;//创建两个Buffered数据流BufferedInputStream bI = null;BufferedOutputStream bO = null;//创建两个字节流FileInputStream fIs =new FileInputStream(srcPath);FileOutputStream fOs = new FileOutputStream(destPath);bI= new BufferedInputStream(fIs);bO =new BufferedOutputStream(fOs);//当返回-1时,就表示文件读取完毕while((bufLen=bI.read(buf))!=-1){//bO.write(buf,0,bufLen);bO.write(buf);/**当拷贝二进制文件时,只能使用字节流进行操作 * 读取多少,就写入多少,使用write(byte[] b,int off,int len); * 如果使用write(byte[] b);代表每次都写入1024个字节,效果基本一致,建议第一种 */}System.out.println("文件拷贝成功!");bI.close();bO.close();}}