文件相关工具 @author SeanDragon
| 19 | * @author SeanDragon |
| 20 | */ |
| 21 | public final class ToolFile { |
| 22 | |
| 23 | private ToolFile() { |
| 24 | throw new UnsupportedOperationException("我是工具类,别初始化我。。。"); |
| 25 | } |
| 26 | |
| 27 | /** |
| 28 | * 根据文件路径获取文件 |
| 29 | * |
| 30 | * @param filePath |
| 31 | * 文件路径 |
| 32 | * |
| 33 | * @return 文件 |
| 34 | */ |
| 35 | public static File getFileByPath(String filePath) { |
| 36 | return ToolStr.isSpace(filePath) ? null : new File(filePath); |
| 37 | } |
| 38 | |
| 39 | /** |
| 40 | * 判断文件是否存在 |
| 41 | * |
| 42 | * @param filePath |
| 43 | * 文件路径 |
| 44 | * |
| 45 | * @return {@code true}: 存在<br>{@code false}: 不存在 |
| 46 | */ |
| 47 | public static boolean isFileExists(String filePath) { |
| 48 | return isFileExists(getFileByPath(filePath)); |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * 判断文件是否存在 |
| 53 | * |
| 54 | * @param file |
| 55 | * 文件 |
| 56 | * |
| 57 | * @return {@code true}: 存在<br>{@code false}: 不存在 |
| 58 | */ |
| 59 | public static boolean isFileExists(File file) { |
| 60 | return file != null && file.exists(); |
| 61 | } |
| 62 | |
| 63 | /** |
| 64 | * 重命名文件 |
| 65 | * |
| 66 | * @param filePath |
| 67 | * 文件路径 |
| 68 | * @param newName |
| 69 | * 新名称 |
| 70 | * |
| 71 | * @return {@code true}: 重命名成功<br>{@code false}: 重命名失败 |
| 72 | */ |
| 73 | public static boolean rename(String filePath, String newName) { |
| 74 | return rename(getFileByPath(filePath), newName); |
| 75 | } |
| 76 | |
| 77 | /** |
| 78 | * 重命名文件 |
nothing calls this directly
no outgoing calls
no test coverage detected