把D:\\12.avi 复制到当前项目目录下的copy.avi中(文件流)

数据源: D:\\12.avi -- 读取数据 -- FileInputStream

目的地:copy.avi   -- 写出数据 -- FileOutputStream


步骤:

   1: 封装数据源

   2: 封装目的地

   3: 读取数据

   4: 写出数据到目的地

   5: 释放资源

 

public class CopyVideo {

public static void main(String[] args) throws IOException {

long star = System.currentTimeMillis();

method1("D:\\12.avi","copy1.avi");

    method2("D:\\12.avi","copy2.avi");

method3("D:\\12.avi","copy3.avi");

        method4("D:\\12.avi","copy4.avi");

long end = System.currentTimeMillis();

System.out.println("共耗时:"+(end-star)+"毫秒");

}

//1,高效的流,一次一个字节数组。

private static void method4(String srcPath, String destPath) throws IOException  {

BufferedInputStream bis=new BufferedInputStream(new FileInputStream(srcPath));

BufferedOutputStreambos=newBufferedOutputStream(newFileOutputStream(destPath));

//读取数据

byte[] buffer=new byte[1024];

int len =0;

while ((len=bis.read())!=-1) {

//写数据到目的地

bos.write(buffer,0,len);  }

bis.close();

bos.close();

}


//,2,高效的流 一次一个字节。

private static void method3(String srcPath, String destPath) throws IOException {

BufferedInputStream bis=new BufferedInputStream(new FileInputStream(srcPath));

BufferedOutputStreambos=newBufferedOutputStream(newFileOutputStream(destPath));

//读取数据

int by=0;

while ((by=bis.read())!=-1) {

//写数据到目的地

bos.write(by);  }

bis.close();

bos.close();

}

/,3,基本的流 一次一个字节数组。

private static void method2(String srcPath, String destPath) throws IOException {

FileInputStream fis=new FileInputStream(srcPath);

FileOutputStream fos=new FileOutputStream(destPath);

//读取数据

byte[] buffer=new byte[1024];

int len=0;

while ((len=fis.read())!=-1) {

//写数据到目的地

fos.write(buffer,0,len);  }

fis.close();

fos.close();

}

/,4,基本的流 一次一个字节。

private static void method1(String srcPath, String destPath) throws IOException {

FileInputStream fis=new FileInputStream(srcPath);

FileOutputStream fos=new FileOutputStream(destPath);

//读取数据

int by=0;

while ((by=fis.read())!=-1) {

//写数据到目的地

fos.write(by);  }

fis.close();

fos.close();

}

}

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值