1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package  com.hanchao.base64;
/***********************
  * file.encoding的简单学习
  * @author:han  
  * @version:1.0      
  * @created:2014-3-28  
  ***********************
  *参考:
  *http://hi.baidu.com/fengchuyang/item/5fe35ecd10b7bb24a0b50ad4
  *
  */
public  class  Test2 {
       
     public  static  void  main(String[] args)  throws  Exception {
           
         /**
          * file.encoding的简单学习
          * 说明:
          * 1.不是操作系统的编码
          * 2.它的值为保存每个程序的main入口的那个java文件的保存编码
          *   (点击文件-->属性-->text file encoding(other的值),
          *   这是使用eclipse 编译器)
          *
          */
         System.out.println( "1.file.encoding : "  + System.getProperty( "file.encoding" ));
         System.out.println( "2.sun.jnu.encoding : "  + System.getProperty( "sun.jnu.encoding" ));
           
         /**
          *  1、文件保存的编码为:GB2312 时
             编译执行之后,得到的结果为:
               
             GB2312
             2、文件保存的编码为:GBK 时
               
             编译执行之后,得到的结果为:
               
             GBK
             3、文件保存的编码为:UTF-8时
               
             编译执行之后,得到的结果为:
               
             UTF-8
             从上面的三个结果可以看出,file.encoding的值并不是操作系统os的默认编码
               
             而是main入口函数所在的类的保存编码.
               
             ****************************************************
             在一个运行的应用程序中
             file.encoding的值只有一个,并且值为入口函数的保存编码的值
          */
           
         String temp =  "abc韩超" ;
         //字符编码
         //temp.getBytes("GBK");
         //temp.getBytes("UTF-8");
         new  String(temp.getBytes( "utf-8" ), "utf-8" );
           
         System.out.println( "NULL:"  + temp);
         System.out.println( "gbk:"  new  String(temp.getBytes(), "GBK" ));
         System.out.println( "UTF-8:"  new  String(temp.getBytes(), "UTF-8" ));
           
           
           
     }
}