把一个文件另存为并重新命名(具体到新的文件名)
FileUtils.copyFile(new File("H:\\Company\\module\\aa.vue"), new File("H:\\Company\\module\\aa_1.vue"));
把一个文件另存为(具体到文件夹)
FileUtils.copyFileToDirectory(new File("H:\\module\\aa.vue"), new File("H:\\仪表板\\module"));
复制文件夹以及里面的文件到另一个文件中
public static void copyDir(String oldPath, String newPath) throws IOException {
File file = new File(oldPath);
String[] filePath = file.list();
if (!(new File(newPath)).exists()) {
(new File(newPath)).mkdir();
}
for (int i = 0; i < filePath.length; i++) {
if ((new File(file + file.separator + filePath[i])).isDirectory()) {
copyDir(file + file.separator + filePath[i], newPath+ file.separator + filePath[i]);
}
if (new File(file + file.separator + filePath[i]).isFile()) {
copyFile(file + file.separator + filePath[i], newPath+ file.separator + filePath[i]);
}
}
}
public static void copyFile(String oldPath, String newPath) throws IOException {
File oldFile = new File(oldPath);
File file = new File(newPath);
FileInputStream in = new FileInputStream(oldFile);
FileOutputStream out = new FileOutputStream(file);;
byte[] buffer=new byte[2097152];
while((in.read(buffer)) != -1){
out.write(buffer);
}
}
public static void main(String[] args) throws IOException {
copyDir(filepath,newfilepath);
}