zoukankan      html  css  js  c++  java
  • 基于Guava实现的文件复制

    需求:现需要将文件D:ABCabc.txt进行一下操作

       1.在文件夹D:ABC下,没有以abc命名的文件夹则创建

       2.将目标文件D:ABCabc.txt复制到abc下

    实现代码:

    /**
         * 以目标文件名创建文件夹,并将目标文件复制到该文件夹下
         *
         * @param srcFilePath 原文件路径
         * @throws Exception Exception
         */
        public static void copyFileToSub(String srcFilePath) throws Exception {
            File srcFile = new File(srcFilePath);
            //文件全名(如:demo.txt)
            String simplePath = Files.simplifyPath(srcFile.getName());
            //不带后缀名文件名(如:demo)
            String fileName = Files.getNameWithoutExtension(simplePath);
            //获取父级路径名
            String parentPath = srcFile.getParent();
            //组装目标文件路径
            String destFilePath = parentPath + File.separator + fileName + File.separator + simplePath;
    
            File destFile = new File(destFilePath);
            //创建目标文件父级目录
            Files.createParentDirs(destFile);
    
            Files.copy(srcFile, destFile);
        }
  • 相关阅读:
    spring快速入门
    Vue整合ElementUI搭建项目
    .Net的Rsa解密
    Maven配置国内仓库
    pom.xml
    SpringBoot文件打包后修改配文件
    .net 过滤器
    c#语法糖汇总
    git修改远程地址
    abp Application层,接口服务层,获取请求的信息
  • 原文地址:https://www.cnblogs.com/watson-ljf/p/6656532.html
Copyright © 2011-2022 走看看