乐趣区

关于java:commonsio下的几个copy-api

  1. copyFile

    • copy file and rename file
    • reserve 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"));
  1. copyFileToDirectory

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

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

    • copy to dest folder as a subfolder
FileUtils.copyDirectoryToDirectory(new File("src/main/resources/folderA/"),new File("src/main/resources/folderB/"));
退出移动版