/**
* 拷贝文件夹到文件夹
*
* */
private void copyDirectory(File oldFile,String newFile){
if (oldFile.isDirectory()){
//copy 文件夹
File[] files = oldFile.listFiles();
if (files!=null||files.length != 0){
int fileSize = files.length;
for (int i = 0;i < fileSize; i++){
if (files[i].isDirectory()){
copyDirectory(files[i],newFile);
}else {
try {
copyFileByChannels(files[i], new File(newFile+files[i].getName()));
}catch (Exception e){
log.error(e.getMessage());
log.error("copy file error filePath:"+files[i].getPath());
break;
}
}
}
}
}
}
private void copyFileByChannels(File source, File dest) throws IOException {
try (FileChannel inputChannel = new FileInputStream(source).getChannel(); FileChannel outputChannel = new FileOutputStream(dest).getChannel()) {
outputChannel.transferFrom(inputChannel, 0, inputChannel.size());
}
}