base64test.java

来自「这是一个关于J2EE的开源包common里的许多组件的示例应用程序,可以借鉴.」· Java 代码 · 共 76 行

JAVA
76
字号
/**
 * Title : Base Dict Class
 * Description : here Description is the function of class, here maybe multirows    
 * @author        kevin
 * @Version       1.0 
 */

package codec;

import org.apache.commons.codec.binary.Base64;
import org.apache.commons.codec.binary.Hex;

/**
 * Class description goes here.
 * @version 1.0  2005-11-7 
 * @author kevin
 */
public class Base64Test
{
	public static void main(String args[])
	{

		//testBase64();
		testHex();
	}

	public static void testBase64()
	{
		Base64 base64 = new Base64();
		String str = "中文";
		byte[] enbytes = null;
		String encodeStr = null;
		byte[] debytes = null;
		String decodeStr = null;
		try
		{
			enbytes = base64.encode(str.getBytes());
			encodeStr = new String(enbytes);
			debytes = base64.decode(enbytes);
			decodeStr = new String(debytes);
		}
		catch(Exception ex)
		{
			System.out.println("编码错误");
		} /*catch (DecoderException ex) {
		 System.out.println("解码错误");
		 }*/
		System.out.println("编码前:" + str);
		System.out.println("编码后:" + encodeStr);
		System.out.println("解码后:" + decodeStr);
	}

	public static void testHex()
	{
		//Hex hex = new Hex();
		String str = "中文";
		char[] enbytes = null;
		String encodeStr = null;
		byte[] debytes = null;
		String decodeStr = null;
		try
		{
			enbytes = Hex.encodeHex(str.getBytes());
			encodeStr = new String(enbytes);
			debytes = Hex.decodeHex(enbytes);
			decodeStr = new String(debytes);
		}
		catch(Exception ex)
		{
			;
		}
		System.out.println("编码前:" + str);
		System.out.println("编码后:" + encodeStr);
		System.out.println("解码后:" + decodeStr);
	}
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?