java URI 编码解码

 import java.io.UnsupportedEncodingException;
/**
* url转码、解码
*/
public class UrlUtil {
private final static String ENCODE = "GBK";
/**
* URL 解码
*
*/
public static String getURLDecoderString(String str) {
String result = "";
if (null == str) {
return "";
}
try {
result = java.net.URLDecoder.decode(str, ENCODE);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return result;
}
/**
* URL 转码
*/
public static String getURLEncoderString(String str) {
String result = "";
if (null == str) {
return "";
}
try {
result = java.net.URLEncoder.encode(str, ENCODE);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return result;
} /**
*
*/
public static void main(String[] args) {
String str = "测试1";
System.out.println(getURLEncoderString(str));
System.out.println(getURLDecoderString(str)); } }
上一篇:MySQL下创建序列及创建自定义函数方法介绍


下一篇:JAVA基础---编码解码