@Test public void testHash() { String file = path + "/image/ali.gif"; assertEquals("文件Hash校验错误", "4FE6FF69F7257F2E8C36B0752B5393BF", FileUtil.fileMD5(new File(file)).toUpperCase()); }
public static String fileMD5(File file) { FileInputStream fileInputStream = null; try { fileInputStream = new FileInputStream(file); byte[] buffer = new byte[8192]; int length; while ((length = fileInputStream.read(buffer)) != -1) { MD5.update(buffer, 0, length); } return new BigInteger(1, MD5.digest()).toString(16); } catch (IOException e) { e.printStackTrace(); return null; } finally { try { if (fileInputStream != null) fileInputStream.close(); } catch (IOException e) { e.printStackTrace(); } } }
FileUtil { public static String fileMD5(File file) { FileInputStream fileInputStream = null; try { fileInputStream = new FileInputStream(file); byte[] buffer = new byte[8192]; int length; while ((length = fileInputStream.read(buffer)) != -1) { MD5.update(buffer, 0, length); } return new BigInteger(1, MD5.digest()).toString(16); } catch (IOException e) { e.printStackTrace(); return null; } finally { try { if (fileInputStream != null) fileInputStream.close(); } catch (IOException e) { e.printStackTrace(); } } } }
FileUtil { public static String fileMD5(File file) { FileInputStream fileInputStream = null; try { fileInputStream = new FileInputStream(file); byte[] buffer = new byte[8192]; int length; while ((length = fileInputStream.read(buffer)) != -1) { MD5.update(buffer, 0, length); } return new BigInteger(1, MD5.digest()).toString(16); } catch (IOException e) { e.printStackTrace(); return null; } finally { try { if (fileInputStream != null) fileInputStream.close(); } catch (IOException e) { e.printStackTrace(); } } }  }
FileUtil { public static String fileMD5(File file) { FileInputStream fileInputStream = null; try { fileInputStream = new FileInputStream(file); byte[] buffer = new byte[8192]; int length; while ((length = fileInputStream.read(buffer)) != -1) { MD5.update(buffer, 0, length); } return new BigInteger(1, MD5.digest()).toString(16); } catch (IOException e) { e.printStackTrace(); return null; } finally { try { if (fileInputStream != null) fileInputStream.close(); } catch (IOException e) { e.printStackTrace(); } } }  static String fileMD5(File file); final static int countLines(File file); final static List<String> lines(File file); final static List<String> lines(File file, String encoding); final static List<String> lines(File file, int lines); final static List<String> lines(File file, int lines, String encoding); final static boolean appendLine(File file, String str); final static boolean appendLine(File file, String str, String encoding); final static boolean write(File file, String str); final static boolean writeAppend(File file, String str); final static boolean write(File file, String str, String encoding); final static boolean writeAppend(File file, String str, String encoding); final static boolean cleanFile(File file); final static String mimeType(String file); final static String fileType(File file); final static Date modifyTime(File file); final static boolean copy(String resourcePath, String targetPath); final static boolean copy(File file, String targetFile); final static boolean createPaths(String paths); final static boolean createFiles(String filePath); final static boolean deleteFile(File file); final static boolean deleteDir(File file); final static boolean deleteBigFile(File file); final static void copyDir(String filePath, String targetPath); final static void copyDir(File filePath, String targetPath); final static List<File> listFile(String path); final static List<File> listFile(String path, boolean child); final static List<File> listFile(File path); final static List<File> listFile(File path, boolean child); final static List<File> listFileAll(File path); final static List<File> listFileFilter(File path, FilenameFilter filter); final static List<File> listFileFilter(File dirPath, final String postfixs); final static List<File> searchFile(File dirPath, String fileName); final static List<File> searchFileReg(File dirPath, String reg); final static String suffix(File file); }
FileUtil { public static String fileMD5(File file) { FileInputStream fileInputStream = null; try { fileInputStream = new FileInputStream(file); byte[] buffer = new byte[8192]; int length; while ((length = fileInputStream.read(buffer)) != -1) { MD5.update(buffer, 0, length); } return new BigInteger(1, MD5.digest()).toString(16); } catch (IOException e) { e.printStackTrace(); return null; } finally { try { if (fileInputStream != null) fileInputStream.close(); } catch (IOException e) { e.printStackTrace(); } } }  static String fileMD5(File file); final static int countLines(File file); final static List<String> lines(File file); final static List<String> lines(File file, String encoding); final static List<String> lines(File file, int lines); final static List<String> lines(File file, int lines, String encoding); final static boolean appendLine(File file, String str); final static boolean appendLine(File file, String str, String encoding); final static boolean write(File file, String str); final static boolean writeAppend(File file, String str); final static boolean write(File file, String str, String encoding); final static boolean writeAppend(File file, String str, String encoding); final static boolean cleanFile(File file); final static String mimeType(String file); final static String fileType(File file); final static Date modifyTime(File file); final static boolean copy(String resourcePath, String targetPath); final static boolean copy(File file, String targetFile); final static boolean createPaths(String paths); final static boolean createFiles(String filePath); final static boolean deleteFile(File file); final static boolean deleteDir(File file); final static boolean deleteBigFile(File file); final static void copyDir(String filePath, String targetPath); final static void copyDir(File filePath, String targetPath); final static List<File> listFile(String path); final static List<File> listFile(String path, boolean child); final static List<File> listFile(File path); final static List<File> listFile(File path, boolean child); final static List<File> listFileAll(File path); final static List<File> listFileFilter(File path, FilenameFilter filter); final static List<File> listFileFilter(File dirPath, final String postfixs); final static List<File> searchFile(File dirPath, String fileName); final static List<File> searchFileReg(File dirPath, String reg); final static String suffix(File file); static MessageDigest MD5; }