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

java乱码相关-转

时间:2014-09-18 16:09:24      阅读:141      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   io   java   ar   div   sp   log   

package test2;

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

import javax.swing.*;

public class test2 {

    public static void main(String[] args) throws UnsupportedEncodingException {
        System.out.println("中文");//1
        
        System.out.println("中文".getBytes());//2

        System.out.println("中文".getBytes("GB2312"));//3

        System.out.println("中文".getBytes("ISO8859_1"));//4
        

        System.out.println(new String("中文".getBytes()));//5

        System.out.println(new String("中文".getBytes(),"GB2312"));//6

        System.out.println(new String("中文".getBytes(),"ISO8859_1"));//7

        System.out.println(new String("中文".getBytes("GB2312")));//8

        System.out.println(new String("中文".getBytes("GB2312"),"GB2312"));//9
        

        System.out.println(new String("中文".getBytes("GB2312"),"ISO8859_1"));//10

        System.out.println(new String("中文".getBytes("ISO8859_1")));//11

        System.out.println(new String("中文".getBytes("ISO8859_1"),"utf-8"));//12

        System.out.println(new String("中文发送短信".getBytes("ISO8859_1"),"utf-8"));//13
        
        //编码与解码
        String cont=URLEncoder.encode(new String("本书  33335  Je t'aime  "), "utf-8");
        
        System.out.println("0:"+cont);      
        System.out.println("0:"+URLEncoder.encode(new String("本书  33335 Je t'aime  "), "gbk"));  
        System.out.println("0:"+URLEncoder.encode(new String("本书 33335 Je t'aime  "), "gb2312"));  
        System.out.println("0:"+URLEncoder.encode(new String("本书  33335 Je t'aime  "), "unicode"));  
        
        String after=URLDecoder.decode(cont, "utf-8");
        System.out.println("1:"+after);
    }

}

 

java乱码相关-转

标签:style   blog   color   io   java   ar   div   sp   log   

原文地址:http://www.cnblogs.com/huhuuu/p/3979220.html

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