zoukankan      html  css  js  c++  java
  • IO流-文件的复制

    1、字节流复制文件:

        public void myTest() {
            // 定义输入和输出流
            FileInputStream fis = null;
            FileOutputStream fos = null;
            try {
                fis = new FileInputStream("E:\电影\黄飞鸿之铁鸡斗蜈蚣.mkv");
                fos = new FileOutputStream("F:\黄飞鸿之铁鸡斗蜈蚣.mkv");
                byte[] b = new byte[1024];
                int len = 0;
                long start = System.currentTimeMillis();// 记录开始复制的时间
                while ((len = fis.read(b)) != -1) {
                    fos.write(b, 0, len);
                }
                long end = System.currentTimeMillis();// 记录结束复制的时间
                System.out.println(end - start);// 算出复制文件所用的时间(ms)
            } catch (IOException e) {
                e.printStackTrace();
            } finally {
                try {
                    if (fos != null) {
                        fos.close();
                    }
                    if (fis != null) {
                        fis.close();
                    }
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }

    2、

        public void myTest() {
            // 定义输入和输出流
            BufferedInputStream bfis = null;
            BufferedOutputStream bfos = null;
            try {
                bfis = new BufferedInputStream(new FileInputStream("E:\电影\黄飞鸿之铁鸡斗蜈蚣.mkv"));
                bfos = new BufferedOutputStream(new FileOutputStream("F:\黄飞鸿之铁鸡斗蜈蚣.mkv"));
                byte[] b = new byte[1024];
                int len = 0;
                long start = System.currentTimeMillis();// 记录开始复制的时间
                while ((len = bfis.read(b)) != -1) {
                    bfos.write(b, 0, len);
                }
                long end = System.currentTimeMillis();// 记录结束复制的时间
                System.out.println(end - start);// 算出复制文件所用的时间(ms)
            } catch (IOException e) {
                e.printStackTrace();
            } finally {
                try {
                    if (bfos != null) {
                        bfos.close();
                    }
                    if (bfis != null) {
                        bfis.close();
                    }
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
  • 相关阅读:
    [Scoi2010]游戏
    HDU3415(单调队列)
    POJ1221(整数划分)
    POJ1050(dp)
    POJ2479(dp)
    HDU1864(背包)
    HDU1175(dfs)
    STL_string.vector中find到的iterator的序号
    Qt532.数值转为16进制(并填充)
    异常处理.VC++
  • 原文地址:https://www.cnblogs.com/a591378955/p/7860130.html
Copyright © 2011-2022 走看看