0
点赞
收藏
分享

微信扫一扫

用IO流来进行复制文件的操作

律楷粑粑 2022-03-27 阅读 77

学习目标:

通过实例案例掌握IO流的实际应用


具体分析

@Test
    public void test() throws IOException {
        //建立一个输入流
        InputStream inputStream=new FileInputStream("D:\\2\\第21章例题-拼图游戏.mp4");
        //建立一个输出流
        OutputStream outputStream=new FileOutputStream("D:\\1\\第21章例题-拼图游戏.mp4");
        //记录运行开始时间
        long start = System.currentTimeMillis();
        //建立缓冲区
        byte[] bytes=new byte[1024*1024*5];
        int len;
        while ((len=inputStream.read(bytes))!=-1){
            //传入一个byte数组,从0开始输出到len结束
            outputStream.write(bytes,0,len);
        }
        //记录运行结束时间
        long end = System.currentTimeMillis();
        //统计运行时间
        System.out.println(end-start);
    }

运行结果:

运行总时间
在这里插入图片描述
复制完成后

在这里插入图片描述在这里插入图片描述


举报

相关推荐

0 条评论