zoukankan      html  css  js  c++  java
  • java文件拷贝

    文件拷贝

    package com.sly.uploadfile.base;
    
    import java.io.File;
    import java.io.FileInputStream;
    import java.io.FileOutputStream;
    
    /**
     * 文件拷贝
     */
    public class CopyDir {
    
        public static void main(String[] args) {
            try {
                copyDir("D:\soft\mysql", "D:\tmp");
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    
        /**
         * 拷贝目录
         */
        public static void copyDir(String srcStr, String destStr) throws Exception {
            File src = new File(srcStr);
            File tempFile = new File(destStr + "//" + src.getName());
            if (src.exists()) {
                // 目录
                if (src.isDirectory()) {
                    if (!tempFile.exists()) {
                        tempFile.mkdir();
                    }
                    File[] files = src.listFiles();
                    for (File f : files) {
                        copyDir(f.getAbsolutePath(), tempFile.getAbsolutePath());
                    }
    
                } else {
                    // 文件
                    // 源文件
                    FileInputStream fin = new FileInputStream(srcStr);
    
                    // 目标文件
                    FileOutputStream fout = new FileOutputStream(destStr + "//" + src.getName());
    
                    int len = -1;
                    byte[] buffer = new byte[1024];
                    while ((len = fin.read(buffer)) != -1) {
                        fout.write(buffer, 0, len);
                    }
                    fout.close();
                    fin.close();
                }
            }
        }
    
    }
  • 相关阅读:
    git 项目代码打包
    jira查看字段
    jmeter压力测试报错:java.net.BindException: Address already in use: connect解决办法
    python 破解验证码
    mysql授权远程登录
    豆瓣api
    利用python开发财务工具
    钉钉发送消息通知
    git使用命令行自动登录
    后宫
  • 原文地址:https://www.cnblogs.com/fmgao-technology/p/13196376.html
Copyright © 2011-2022 走看看