| | |
| | | import java.security.MessageDigest; |
| | | import java.text.DecimalFormat; |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | | |
| | | /** |
| | | * 文件帮助类 |
| | |
| | | } |
| | | |
| | | /** |
| | | * 获取文件大小 |
| | | */ |
| | | public static String getSizes(double mbNumber) { |
| | | if (mbNumber < StaticData.D1024) { |
| | | return new DecimalFormat("#.##MB").format(mbNumber); |
| | | } |
| | | |
| | | double gbNumber = mbNumber / StaticData.D1024; |
| | | if (gbNumber < StaticData.D1024) { |
| | | return new DecimalFormat("#.##GB").format(gbNumber); |
| | | } |
| | | |
| | | double tbNumber = gbNumber / StaticData.D1024; |
| | | |
| | | return new DecimalFormat("#.##TB").format(tbNumber); |
| | | } |
| | | |
| | | /** |
| | | * byte转MB |
| | | */ |
| | | public static double sizeToMb(long size) { |
| | |
| | | * @param file 文件 |
| | | */ |
| | | public static void deleteFiles(File file) { |
| | | if (file == null || !file.exists()) { |
| | | if (null == file || !file.exists()) { |
| | | return; |
| | | } |
| | | |
| | | if (file.isDirectory()) { |
| | | File[] files = file.listFiles(); |
| | | for (File f : files) { |
| | | if (f.isDirectory()) { |
| | | deleteFiles(f); |
| | | } else { |
| | | f.delete(); |
| | | if (null != files && files.length > 0) { |
| | | for (File f : files) { |
| | | if (f.isDirectory()) { |
| | | deleteFiles(f); |
| | | } else { |
| | | f.delete(); |
| | | } |
| | | } |
| | | } |
| | | } |
| | |
| | | |
| | | return builder.toString(); |
| | | } |
| | | |
| | | /** |
| | | * 根据路径获取文件 |
| | | */ |
| | | public static void getFilesByPath(List<File> list, String path) { |
| | | File file = new File(path); |
| | | if (file.isDirectory()) { |
| | | File[] files = file.listFiles(); |
| | | if (null == files) { |
| | | return; |
| | | } |
| | | |
| | | for (File f : files) { |
| | | if (f.isDirectory()) { |
| | | getFilesByPath(list, f.getPath()); |
| | | } else { |
| | | list.add(f); |
| | | } |
| | | } |
| | | } else { |
| | | list.add(file); |
| | | } |
| | | } |
| | | } |