A股上市公司传智教育(股票代码 003032)旗下技术交流社区北京昌平校区

 找回密码
 加入黑马

QQ登录

只需一步,快速开始

© 小丑的眼泪 初级黑马   /  2015-4-24 19:16  /  2366 人查看  /  1 人回复  /   0 人收藏 转载请遵从CC协议 禁止商业使用本文

6黑马币
编写程序,采用多种方式,把d:\\video01.avi的内容复制到d:\\video02.avi
方式1:基本字节流一次读写一个字节
方式2:基本字节流一次读写一个字节数组
方式3:高效字节流一次读写一个字节
方式4:高效字节流一次读写一个字节数组

最佳答案

查看完整内容

public class CopyVideo { public static void main(String[] args) throws IOException { long start = System.currentTimeMillis(); //method1("D:\\video01.avi ", "D:\\video02.avi "); //method2("D:\\video01.avi ", "D:\\video02.avi "); //method3("D:\\video01.avi ", "D:\\video02.avi "); method4("D:\\video01.avi ", "D:\\video02.avi "); long end = System.currentTimeMillis(); Sy ...

1 个回复

倒序浏览
public class CopyVideo {
        public static void main(String[] args) throws IOException {
                long start = System.currentTimeMillis();
                //method1("D:\\video01.avi

", "D:\\video02.avi

");
                //method2("D:\\video01.avi

", "D:\\video02.avi

");
                //method3("D:\\video01.avi

", "D:\\video02.avi

");
                method4("D:\\video01.avi

", "D:\\video02.avi

");
                long end = System.currentTimeMillis();
                System.out.println("共耗时: "+ (end-start) +"毫秒");
        }

        //基本的流 一次一个字节
        public 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();
        }

        //基本的流 一次一个字节数组
        public 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(buffer)) != -1){
                        //写数据到目的地
                        fos.write(buffer, 0, len);
                }
                fos.close();
                fis.close();
        }

        //高效的流 一次一个字节
        public static void method3(String srcPath, String destPath) throws IOException {
                BufferedInputStream bis = new BufferedInputStream(new FileInputStream(srcPath));
                BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(destPath));
                //读取数据
                int by = 0;
                while (( by=bis.read()) != -1) {
                        //写数据到目的地
                        bos.write(by);
                }
                bos.close();
                bis.close();
        }
       
        //高效的流 一次一个字节数组
        public static void method4(String srcPath, String destPath) throws IOException {
                BufferedInputStream bis = new BufferedInputStream(new FileInputStream(srcPath));
                BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(destPath));
                //读取数据
                byte[] buffer = new byte[1024];
                int len = 0;
                while ((len = bis.read(buffer)) != -1) {
                        //写数据到目的地
                        bos.write(buffer, 0, len);
                }
                bos.close();
                bis.close();
        }
}
回复 使用道具 举报
您需要登录后才可以回帖 登录 | 加入黑马