ÎļþÃû´Ó se-system/src/main/java/com/terra/system/helper/FileHelper.java ÐÞ¸Ä |
| | |
| | | package com.terra.system.helper; |
| | | package com.terra.common.helper; |
| | | |
| | | import com.terra.common.entity.all.StaticData; |
| | | import com.terra.system.entity.data.MetaFileEntity; |
| | | //import com.twmacinta.util.MD5; |
| | | import org.apache.commons.codec.digest.DigestUtils; |
| | | //import org.apache.commons.codec.digest.DigestUtils; |
| | | import org.apache.commons.logging.Log; |
| | | import org.apache.commons.logging.LogFactory; |
| | | |
| | |
| | | import java.nio.ByteBuffer; |
| | | import java.nio.channels.FileChannel; |
| | | import java.nio.charset.StandardCharsets; |
| | | import java.nio.file.Files; |
| | | import java.security.MessageDigest; |
| | | import java.text.DecimalFormat; |
| | | import java.util.List; |
| | |
| | | /** |
| | | * 3.è·åæä»¶MD5ç ï¼JDKï¼ |
| | | */ |
| | | public static String getMd5ByJdk(String filePath) throws IOException { |
| | | /*public static String getMd5ByJdk(String filePath) throws IOException { |
| | | FileInputStream fileStream = new FileInputStream(filePath); |
| | | String md5 = DigestUtils.md5Hex(fileStream); |
| | | fileStream.close(); |
| | | |
| | | return md5; |
| | | } |
| | | }*/ |
| | | |
| | | /** |
| | | * 2.è·åå¿«é MD5 ç |
| | | */ |
| | | public static String getFastMd5(String filePath) throws IOException { |
| | | /*String hash = MD5.asHex(MD5.getHash(new File(filePath))); |
| | | /*public static String getFastMd5(String filePath) throws IOException { |
| | | String hash = MD5.asHex(MD5.getHash(new File(filePath))); |
| | | |
| | | MD5 md5 = new MD5(); |
| | | md5.Update(hash, null); |
| | | |
| | | return md5.asHex();*/ |
| | | return md5.asHex(); |
| | | |
| | | return null; |
| | | } |
| | | |
| | | /** |
| | | * å 餿件 |
| | | */ |
| | | public static void deleteFiles(List<MetaFileEntity> list) { |
| | | try { |
| | | for (MetaFileEntity mf : list) { |
| | | File f = new File(mf.getPath()); |
| | | if (f.exists()) { |
| | | f.delete(); |
| | | } |
| | | } |
| | | } catch (Exception ex) { |
| | | log.error(ex.getMessage(), ex); |
| | | } |
| | | } |
| | | }*/ |
| | | |
| | | /** |
| | | * å 餿件夹 |
| | |
| | | |
| | | return byteToHexString(b); |
| | | } catch (Exception ex) { |
| | | ex.printStackTrace(); |
| | | log.error(ex.getMessage(), ex); |
| | | return null; |
| | | } finally { |
| | | try { |
| | |
| | | fis.close(); |
| | | } |
| | | } catch (IOException ex) { |
| | | ex.printStackTrace(); |
| | | log.error(ex.getMessage(), ex); |
| | | } |
| | | } |
| | | } |
| | |
| | | InputStream is = null; |
| | | OutputStream os = null; |
| | | try { |
| | | is = new FileInputStream(src); |
| | | os = new FileOutputStream(dest); |
| | | is = Files.newInputStream(src.toPath()); |
| | | os = Files.newOutputStream(dest.toPath()); |
| | | |
| | | byte[] buffer = new byte[1024]; |
| | | |
| | |
| | | os.write(buffer, 0, length); |
| | | } |
| | | } finally { |
| | | os.close(); |
| | | is.close(); |
| | | if (os != null) os.close(); |
| | | if (is != null) is.close(); |
| | | } |
| | | } |
| | | } |