📄 base64test.java
字号:
/**
* 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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -