Here you can find the source of getMD5(File file)
Parameter | Description |
---|---|
file | the File to create Hash from. |
Parameter | Description |
---|---|
Exception | an exception |
public static String getMD5(File file) throws Exception
//package com.java2s; /*// w ww.jav a 2 s . c om * Copyright (c) 2015 "JackWhite20" * * This file is part of PatchyAPI. * * PatchyAPI is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see <http://www.gnu.org/licenses/>. */ import javax.xml.bind.DatatypeConverter; import java.io.File; import java.nio.file.Files; import java.nio.file.Paths; import java.security.MessageDigest; public class Main { /** * Get the MD5 Hash from the given File. * * @param file the File to create Hash from. * @return the Hash as Hex String. * @throws Exception */ public static String getMD5(File file) throws Exception { String path = file.getAbsolutePath(); MessageDigest md = MessageDigest.getInstance("MD5"); md.update(Files.readAllBytes(Paths.get(path))); return DatatypeConverter.printHexBinary(md.digest()).toUpperCase(); } }