UTF-8与GBK互转

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;

public class Test {
	public static void main(String[] args){
		//测试中文,英文,字符转换
		String str = "中华人民共和国 china !@#$%^,./";
		try {
			str = URLEncoder.encode(str, "UTF-8");
			System.out.println("UTF-8:"+str);
			System.out.println("G B K:"+URLDecoder.decode(str,"UTF-8"));
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
	}
}

后台输出:
UTF-8:%E4%B8%AD%E5%8D%8E%E4%BA%BA%E6%B0%91%E5%85%B1%E5%92%8C%E5%9B%BD+china+%21%40%23%24%25%5E%2C.%2F
G B K:中华人民共和国 china !@#$%^,./

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