码迷,mamicode.com
首页 > 编程语言 > 详细

java中的中文字符转码技术

时间:2018-04-12 13:32:44      阅读:193      评论:0      收藏:0      [点我收藏+]

标签:style   com   ati   ace   nts   技术   cat   .net   url   

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();  
    }  
}
}

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

java中的中文字符转码技术

标签:style   com   ati   ace   nts   技术   cat   .net   url   

原文地址:https://www.cnblogs.com/yinyl/p/8806623.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!