复制文件 @param resource 源文件 @param target 目标文件 @return 是否成功
(File resource, File target)
| 352 | * @return 是否成功 |
| 353 | */ |
| 354 | public static boolean copy(File resource, File target) throws IOException { |
| 355 | if (resource == null) { |
| 356 | logger.error("copy resource is null"); |
| 357 | return false; |
| 358 | } |
| 359 | if (resource.isFile()) { |
| 360 | return copyFile(resource, target); |
| 361 | } |
| 362 | File[] files = resource.listFiles(); |
| 363 | if (files == null || files.length == 0) { |
| 364 | return target.mkdirs(); |
| 365 | } |
| 366 | target.mkdirs(); |
| 367 | for (File file : files) { |
| 368 | String targetFilePath = file.getAbsolutePath().substring(resource.getAbsolutePath().length()); |
| 369 | File targetFile = new File(target + "/" + targetFilePath); |
| 370 | if (file.isDirectory()) { |
| 371 | targetFile.mkdirs(); |
| 372 | copy(file, targetFile); |
| 373 | } else { |
| 374 | copyFile(file, targetFile); |
| 375 | } |
| 376 | } |
| 377 | return true; |
| 378 | |
| 379 | } |
| 380 | |
| 381 | /** |
| 382 | * 复制文件 |