1.å¦ä½è®¡ç®InputstreamçMD5
2.ioutils.tostringä¼closeå
3.java.lang.UnsupportedClassVersionError: URLCat:Unsupported major.minor version 51.0
å¦ä½è®¡ç®InputstreamçMD5
é¦å ï¼æç®åçæ¹å¼å°±æ¯æä½ ç两è¡ä»£ç ç»åèµ·æ¥ï¼å ä¿åæ件ï¼å读åæ件æµè®¡ç®MD5ï¼
public static String copyInputStreamToFileAndGetMd5Hex(InputStream inputStream,iapp源码提取工具 File file) throws IOException {
FileUtils.copyInputStreamToFile(inputStream, file);
return DigestUtils.md5Hex(new FileInputStream(file));
}
å½ç¶è¿æ ·åè¦å¯¹åä¸ä¸ªæµè¯»å两次ï¼æ¾å¾ä¸å¤ä½ç¢³ç¯ä¿ã
æ¤æ¶å¯ä»¥çä¸DigestUtilsæºç ï¼è¿½å ¶æ ¹æº¯å ¶æºå¯ä»¥çå°ï¼
public static MessageDigest updateDigest(final MessageDigest digest, final InputStream data) throws IOException {
final byte[] buffer = new byte[STREAM_BUFFER_LENGTH];
int read = data.read(buffer, 0, STREAM_BUFFER_LENGTH);
while (read > -1) {
digest.update(buffer, 0, read);
read = data.read(buffer, 0, STREAM_BUFFER_LENGTH);
}
return digest;
}
ä¹ä¸æ¯å¤é«çº§çææ¯ï¼å°±æ¯ææ´ä¸ªInputStreamææé¿åº¦çåèæ°ç»é个MD5ã
åççFileUtils.copyInputStreamToFileæºç çè¿½æ ¹æº¯æºå®ç°ï¼
public static long copyLarge(InputStream input, OutputStream output, byte[] buffer) throws IOException {
long count;
int n;
for(count = 0L; -1 != (n = input.read(buffer)); count += (long)n) {
output.write(buffer, 0, n);
}
return count;
}
åæ ·ä¹æ¯è®²InputStreamææçåèæ°ç»ï¼é个åå°ç®æ æ件ä¸ã
é£ä¹ï¼ä¸¤è ç»åèµ·æ¥ä»£ç ä¹å°±å¥½åäºï¼
public static String copyInputStreamToFileAndGetMd5Hex(InputStream inputStream, File file) throws IOException {
MessageDigest digest = DigestUtils.getMd5Digest();
FileOutputStream outputStream = null;
try {
outputStream = new FileOutputStream(file);
byte[] buffer = new byte[];
int read = inputStream.read(buffer);
while (read > -1) {
// 计ç®MD5,顺便åå°æ件
digest.update(buffer, 0, read);
outputStream.write(buffer, 0, read);
read = inputStream.read(buffer);
}
} finally {
IOUtils.closeQuietly(outputStream);
}
return Hex.encodeHexString(digest.digest());
}
ioutils.tostringä¼closeå
æºä»£ç 没æä½ç°åºæ¥ï¼ä½æ¯å®é è°ç¨å®ioutils.tostringï¼åæµæ¯å ³éäºï¼å次è°ç¨çæ¶åä¼æ¥é
java.lang.UnsupportedClassVersionError: URLCat:Unsupported major.minor version .0
å®çæææ¯è¯´ï¼ç¨åºç¼è¯çæ¶åç¨äºä¸ä¸ªè¾é«çæ¬çJDK,ä½æ¯å¨ç¨åºè¿è¡çæ¶åå´ç¨äºä¸ä¸ªè¾ä½çæ¬çjdkãæå¨eclipseéé¢å ç¨jdk1.7å°ç¨åºè·äºä¸éï¼ç¶åç¨jdk1.6è·ç¨åºå°±ä¼åºç°ä¸è¿°çé误ï¼åå å°±æ¯å¨ç¨jdk1.7è·äºç¨åºæ²¡æé®é¢ï¼è¿æ¶åå¨å·¥ç¨çbinç®å½ä¸é¢å°±äº§çäºç¸åºäºjdk1.7çclassæ件ï¼ä¸æ¬¡åç¨jdk1.6è·è¿ä¸ªå·¥ç¨ï¼ç±äºclassæ件æ¯æjdk1.7产ççï¼æ以ç¨åºè·ä¸éä¹ä¸è¶³ä¸ºå¥ï¼ 解å³çæ¹æ³å°±æ¯å¨ç¬¬ä¸æ¬¡è·è¿ä¸ªå·¥ç¨çæ¶åç¨ç¨è¾ä½çæ¬çjdk,ç¶ååç¨è¾é«çæ¬çjdkè·æè æ¯ä¸ç´ç¨è¾é«çæ¬çjdkè·ãä¹å°±æ¯JDKè¾é«çæ¬å ¼å®¹è¾ä½çæ¬ãä½æ¯è¾ä½çæ¬å´æ¯æ æ³å®æè¾é«çæ¬çåè½ãè¿ä¹æ¯ç¬¦åé»è¾çã