码迷,mamicode.com
首页 > 编程语言 > 详细

java IO流文件拷贝文件(字节流标准写法)

时间:2019-03-29 00:35:47      阅读:205      评论:0      收藏:0      [点我收藏+]

标签:拷贝文件   class   java   final   fileinput   文件拷贝   拷贝   file   new   

public static void copyFile(String srcPath, String destPath) {

        FileInputStream fis = null;
        FileOutputStream fos = null;
        try {
            fis = new FileInputStream(srcPath);
            fos = new FileOutputStream(destPath);

            byte[] byt = new byte[1024 * 1024];
            int len = 0;
            while ((len = fis.read(byt)) != -1) {

                fos.write(byt, 0, len);
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        } finally {

            try {
                if (fis != null) {
                    fis.close();
                }
            } catch (IOException e) {
                throw new RuntimeException(e);
            } finally {
                if (fos != null) {
                    try {
                        fos.close();
                    } catch (IOException e) {
                        throw new RuntimeException(e);
                    }
                }

            }
        }

    }

 

java IO流文件拷贝文件(字节流标准写法)

标签:拷贝文件   class   java   final   fileinput   文件拷贝   拷贝   file   new   

原文地址:https://www.cnblogs.com/sheng-sjk/p/9833252.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!