删除文件 自动路径 jar启动时使用外部路径 IDE启动时使用内部路径 @param path 路径 @return
(String path)
| 620 | * @return |
| 621 | */ |
| 622 | public static Boolean autoDeleteFile(String path){ |
| 623 | Boolean state = null; |
| 624 | File file = new File(PathUtil.autoRootPath()+File.separator+path); |
| 625 | |
| 626 | // 路径为文件且不为空则进行删除 |
| 627 | if (file.isFile() && file.exists()) { |
| 628 | state = file.delete(); |
| 629 | |
| 630 | if(!state){ |
| 631 | try { |
| 632 | //清空内容 |
| 633 | org.apache.commons.io.FileUtils.writeStringToFile(file, "", "UTF-8"); |
| 634 | state = file.delete(); |
| 635 | } catch (IOException e) { |
| 636 | // e.printStackTrace(); |
| 637 | if (logger.isErrorEnabled()) { |
| 638 | logger.error("删除文件",e); |
| 639 | } |
| 640 | } |
| 641 | |
| 642 | } |
| 643 | } |
| 644 | return state; |
| 645 | } |
| 646 | /** |
| 647 | * 删除目录 自动路径 jar启动时使用外部路径 IDE启动时使用内部路径 |
| 648 | * @param path 路径 (格式"file"+File.separator+"目录"+File.separator) |
nothing calls this directly
no test coverage detected