删除目录 @param dir 对象
(File dir)
| 548 | * @param dir 对象 |
| 549 | */ |
| 550 | public static Boolean removeDirectory(File dir){ |
| 551 | Boolean state = null; |
| 552 | if(dir.isDirectory()){ |
| 553 | state = org.apache.commons.io.FileUtils.deleteQuietly(dir); |
| 554 | if(!state){ |
| 555 | //清空内容 |
| 556 | String[] extensions = null;//后缀名{"doc", "pdf"} |
| 557 | boolean recursive = true;//是否递归 |
| 558 | |
| 559 | Collection<File> files = FileUtils.listFiles(dir, extensions, recursive); |
| 560 | // 迭代输出 |
| 561 | for (Iterator<File> iterator = files.iterator(); iterator.hasNext();) { |
| 562 | File file = iterator.next(); |
| 563 | if(!file.isHidden()){//不是隐蔽文件 |
| 564 | //清空内容 |
| 565 | try { |
| 566 | org.apache.commons.io.FileUtils.writeStringToFile(file, "", "UTF-8"); |
| 567 | state = file.delete(); |
| 568 | |
| 569 | } catch (IOException e) { |
| 570 | // TODO Auto-generated catch block |
| 571 | // e.printStackTrace(); |
| 572 | if (logger.isErrorEnabled()) { |
| 573 | logger.error("删除目录",e); |
| 574 | } |
| 575 | } |
| 576 | } |
| 577 | } |
| 578 | } |
| 579 | } |
| 580 | |
| 581 | return state; |
| 582 | |
| 583 | } |
| 584 | |
| 585 | /** |
| 586 | * 生成文件夹 自动路径 jar启动时使用外部路径 IDE启动时使用内部路径 |
no test coverage detected