| | |
| | | package com.lf.server.helper; |
| | | |
| | | import com.lf.server.entity.data.MetaFileEntity; |
| | | import com.lf.server.service.data.UploaderService; |
| | | import org.apache.commons.codec.digest.DigestUtils; |
| | | import org.apache.commons.logging.Log; |
| | | import org.apache.commons.logging.LogFactory; |
| | |
| | | public static final double D1050 = 1050.0; |
| | | |
| | | private final static Log log = LogFactory.getLog(FileHelper.class); |
| | | |
| | | /** |
| | | * 获取文件名 |
| | | * |
| | | * @param file |
| | | * @return |
| | | */ |
| | | public static String getFileName(String file) { |
| | | int idx = file.lastIndexOf(File.separator); |
| | | if (idx > -1) { |
| | | return file.substring(idx + 1); |
| | | } |
| | | |
| | | return ""; |
| | | } |
| | | |
| | | /** |
| | | * 获取文件扩展名 |
| | |
| | | log.error(ex.getMessage(), ex); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 删除文件夹 |
| | | * |
| | | * @param dir 文件夹 |
| | | */ |
| | | public static void deleteDir(String dir) { |
| | | File file = new File(dir); |
| | | |
| | | deleteFiles(file); |
| | | } |
| | | |
| | | /** |
| | | * 级联删除文件 |
| | | * |
| | | * @param file 文件 |
| | | */ |
| | | public static void deleteFiles(File file) { |
| | | if (file == null || !file.exists()) { |
| | | return; |
| | | } |
| | | |
| | | if (file.isDirectory()) { |
| | | File[] files = file.listFiles(); |
| | | for (File f : files) { |
| | | if (f.isDirectory()) { |
| | | deleteFiles(f); |
| | | } else { |
| | | f.delete(); |
| | | } |
| | | } |
| | | } |
| | | |
| | | file.delete(); |
| | | } |
| | | |
| | | /** |
| | | * 获取相对路径 |
| | | * |
| | | * @param file 文件 |
| | | * @return 相对路径 |
| | | */ |
| | | public static String getRelativePath(String file) { |
| | | if (StringHelper.isEmpty(file)) { |
| | | return null; |
| | | } |
| | | |
| | | int idx = file.lastIndexOf(File.separator); |
| | | int start = file.lastIndexOf(File.separator, idx - 1); |
| | | |
| | | return file.substring(start + 1); |
| | | } |
| | | |
| | | /** |
| | | * 获取路径 |
| | | * |
| | | * @param file 文件 |
| | | * @return 文件路径 |
| | | */ |
| | | public static String getPath(String file) { |
| | | if (StringHelper.isEmpty(file)) { |
| | | return null; |
| | | } |
| | | |
| | | int end = file.lastIndexOf(File.separator); |
| | | |
| | | return file.substring(0, end); |
| | | } |
| | | } |