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();
                }
            }
        }
  • 相关阅读:
    <c:forEach>详解
    JSP基本_JSTL
    鼠标显示效果的形状设置
    linux7.3+nginx1.1+tomcat8.5 搭建负载均衡
    安装zabbix
    Centos7 systemctl使用
    Centos7 yum安装 Lnmp以及Lamp
    Centos7 LAMP环境下安装zabbix3.0
    centos 7.0 搭建LAMP环境
    mysql 配置参数详解
  • 原文地址:https://www.cnblogs.com/a591378955/p/7860130.html
Copyright © 2011-2022 走看看