java中的中文字符转码技术


package com.yin.test;

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

/**
 * @author User
 *
 */
public class MyTestClass
{
public static void main(String[] args)
{
      
    String str = "测试字符转换 a beautiful girl"; //默认环境,已是UTF-8编码  
    try {  
        String strGBK = URLEncoder.encode(str, "GBK");  
        System.out.println(strGBK);  
        String strUTF8 = URLDecoder.decode(str, "UTF-8");  
        System.out.println(strUTF8);  
    } catch (UnsupportedEncodingException e) {  
        e.printStackTrace();  
    }  
}
}

转码技术一般用于数据传递,防止中文乱的出现,导致数据异常~


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM