JAVA实现GBK,UTF-8与中文互转

import java.io.UnsupportedEncodingException;  
import java.net.URLDecoder;  
import java.net.URLEncoder;  
  
public class EncodeAndDecode {  
    public static void main(String[] args) throws UnsupportedEncodingException {  
        System.out  
                .println(URLDecoder.decode("%D6%D0%CE%C4%B9%FA%BC%CA", "GBK"));// GBK编码转中文  
        System.out.println(URLEncoder.encode("中文国际", "GBK")); // 中文编码转GBK  
        System.out.println(URLDecoder.decode(  
                "%E4%B8%AD%E6%96%87%E5%9B%BD%E9%99%85", "UTF-8"));// UTF-8编码转中文  
        System.out.println(URLEncoder.encode("中文国际", "UTF-8")); // UTF-8编码转中文  
    }  
}  

转载于:https://my.oschina.net/niclee94/blog/983534

你可能感兴趣的:(JAVA实现GBK,UTF-8与中文互转)