java¼ÆËãÎļþºÍ×Ö·û´®µÄmd5Âë
import java.io.File;
import java.io.FileInputStream;
import java.nio.MappedByteBuffer;
import java.nio.channels.FileChannel;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
public class MD5Util
{
private static char md5Chars[] =
{ '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd',
'e', 'f' };
private static MessageDigest messagedigest;
/*»ñȡһ¸öÎļþµÄmd5Âë */
public static String getFileMD5String(File file) throws Exception
{
messagedigest = MessageDigest.getInstance("MD5");
FileInputStream in = new FileInputStream(file);
FileChannel ch = in.getChannel();
MappedByteBuffer byteBuffer = ch.map(FileChannel.MapMode.READ_ONLY, 0,
file.length());
messagedigest.update(byteBuffer);
return bufferToHex(messagedigest.digest());
}
/*»ñȡһ¸ö×Ö·û´®µÄmd5Âë */
public static String getStringMD5String(String str) throws Exception
{
messagedigest = MessageDigest.getInstance("MD5");
messagedigest.update(str.getBytes());
return bufferToHex(messagedigest.digest());
}
/*ÑéÖ¤Ò»¸ö×Ö·û´®ºÍÒ»¸öMD5ÂëÊÇ·ñÏàµÈ */
public static boolean check(String str,String md5) throws Exception
{
if(getStringMD5String(str).equals(md5))
return true;
else
return false;
}
/*ÑéÖ¤Ò»¸öÎļþºÍÒ»¸öMD5ÂëÊÇ·ñÏàµÈ */
public static boolean check(File f,String md5) throws Exception
{
if(getFileMD5String(f).equals(md5))
return true;
else
return false;
}
private static String bufferToHex(byte bytes[])
{
return bufferToHex(bytes, 0, bytes.length);
}
private static String bufferToHex(byte b
Ïà¹ØÎĵµ£º
Java IOµÄÒ»°ãʹÓÃÔÔò£º
Ò»¡¢°´Êý¾ÝÀ´Ô´£¨È¥Ïò£©·ÖÀࣺ
1¡¢ÊÇÎļþ£º FileInputStream, FileOutputStream, FileReader, FileWriter
2¡¢ÊÇbyte[]£ºByteArrayInputStream, ByteArrayOutputStream
3¡¢ÊÇChar[]: CharArrayReader, CharArrayWriter
4¡¢ÊÇString: StringBufferInputStream, StringReader, StringWriter
5¡¢ ......
ͨ¹ý·´Éä´´½¨ÐÂÀàʾÀýµÄÁ½ÖÖ·½Ê½¼°±È½Ï
×÷ÕßBLOG£ºhttp://blog.csdn.net/fenglibing
ͨ¹ý·´Éä´´½¨ÐµÄÀàʾÀý£¬ÓÐÁ½ÖÖ·½Ê½£º
Class.newInstance()
Constructor.newInstance()
ÒÔ϶ÔÁ½ÖÖµ÷Ó÷½Ê½¸øÒԱȽÏ˵Ã÷£º
l Class.newInstance() Ö»ÄÜ ......
ä¯ÀÀÆ÷²»Ö§³ÖjavaµÄ½â¾ö°ì·¨2008-07-09 11:45ä¯ÀÀÆ÷²»ÄÜÏÔÊ¾ÍøÒ³µÄijЩÄÚÈÝ£¬Ö»ÏÔʾһ¸ö»ÒÉ«µÄ¿ò£¬Ìáʾ²»Ö§³ÖJAVA¡£ ÕâÊÇÒòΪÄúµÄä¯ÀÀÆ÷ÐèÒªÓÐÖ§³ÖJavaµÄ¹¦ÄܲÅÄÜ¿´µ½£¬ÓпÉÄÜÊÇÄãµÄä¯ÀÀÆ÷ûÓа²×°javaÐéÄâ»úµÄÖ§³Ö£¬Ò²ÓпÉÄÜÊÇÄãµÄä¯ÀÀÆ÷½ûÖ¹ÁËJavaµÄ¹¦ÄÜ¡£Çë°´ÏÂÃæÌáʾ´ò¿ªÄãµÄä¯ÀÀÆ÷µÄjavaÉèÖá£
(1)¡¢Èç¹ûÄãµÄ²Ù×÷ÏµÍ ......
java³£Óü¯ºÏÀàÏê½â£¨ÓÐÀý×Ó£¬¾µäÄÅ£¡£¡£¡¼¯ºÏÀàºýÍ¿µÄÀ´¿´°¡£¡£¡£©
Collections Framework
¼¯ºÏ¿ò¼ÜÊÇÒ»¸öͳһµÄ¼Ü¹¹,ÓÃÀ´±íʾºÍ²Ù×÷¼¯ºÏ.
¼¯ºÏ¿ò¼ÜÖ÷ÒªÊÇÓɽӿÚ,³éÏóÀàºÍʵÏÖÀ๹³É.
½Ó¿Ú:À¶É«£»ÊµÏÖÀࣺºìÉ«
Collection
|_____Set(HashSet)
| |_____SortedSet(Tree ......
Ãô½Ý¿ª·¢µÄÀíÄîÒѾÁ÷ÐÐÁ˺ܳ¤µÄʱ¼ä£¬ÔÚÃô½Ý¿ª·¢ÖеĿª·¢µü´ú½×¶ÎÖУ¬ÎÒÃÇ¿ÉÒÔͨ¹ýÎå¸ö²½Ö裬À´ÓÐЧµÄÌá¸ßÕû¸öÏîÄ¿µÄ´úÂëÖÊÁ¿¡£
JavaÏîÄ¿¿ª·¢¹ý³ÌÖУ¬ÓÉÓÚ¿ª·¢ÈËÔ±µÄ¾Ñé¡¢Java´úÂë±àдϰ¹ß£¬ÒÔ¼°È±·¦Í³Ò»µÄ±ê×¼ºÍ¹ÜÀíÁ÷³Ì£¬ÍùÍùµ¼ÖÂÕû¸öÏîÄ¿µÄ´úÂëÖÊÁ¿½Ï²î£¬ÄÑÓÚά »¤£¬ÐèÒª½Ï´óµÄ²âÊÔͶÈëºÍÖÜÆÚµÈÎÊÌâ¡£ÕâЩÎÊÌâÔÚÒ»¸öÏ ......