学堂 学堂 学堂公众号手机端

commons-io下的几个copy api

lewis 5年前 (2020-08-14) 阅读数 6 #技术

copyFile

copy file and rename filereserve the file's last modified date/times(cp -p)both src and dest should be file
FileUtils.copyFile(new File("./folderA/a.txt"),new File("./folderB"));

copyFileToDirectory

copy file to dest folderdest must be folder, if not exist, mkdirs
FileUtils.copyFileToDirectory(new File("src/main/resources/folderA/a.txt"),new File("src/main/resources/folderB/"));

copyDirectory


copy all files in one folder to another foldersrc must be folder, or throw exceptionfor dest folder, mkdirs
FileUtils.copyDirectory(new File("src/main/resources/folderA/"),new File("src/main/resources/folderB/c.txt"));

copyDirectoryToDirectory

copy to dest folder as a subfolder
FileUtils.copyDirectoryToDirectory(new File("src/main/resources/folderA/"),new File("src/main/resources/folderB/"));
版权声明

本文仅代表作者观点,不代表博信信息网立场。

热门