Java学习 之 转码(URLDecoder,URLEncoder)

 直接看代码最简单明了,贴上:
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;


public class URLDecoderTest {
	
	public static void main(String[] args) throws UnsupportedEncodingException {
		// 将application/x-www-from-urlencoded字符串转换成普通字符串
		String keyWord = URLDecoder.decode("%E6%9D%8E%E5%88%9A", "UTF-8");
		System.out.println(keyWord);
		
		// 将普通字符创转换成application/x-www-from-urlencoded字符串
		String urlString = URLEncoder.encode("爱我中华", "GBK");
		System.out.println(urlString);
	}
}

 

 

 

你可能感兴趣的:(java,.net)