1、GBK编码
java的默认编码方式是GBK编码方式,一个中文对应2个字节,一个英文占一个字节
2、utf-8
utf-8的编码方式中,一个中文对应三个字节,一个英文占一个字节
3、utf-16be
utf-16be编码方式是java的编码方式,不管是中文还是英文都占两个字节
4、ansi编码
ansi主要用在中文电脑的文本自带的编码方式,比如txt文本中只有ansi编码方式才能正确显示中文
这里写个关于java的编码的代码,从慕课网上学习的,很不错的一个网站
package com.skyL;
public class Encode {
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
String str = "爱慕课ABC";
byte[] byte1 = str.getBytes();
for(byte bt : byte1){
System.out.print(Integer.toHexString(bt & 0xff) + " ");
}
System.out.println();
String str1 = new String(byte1);
System.out.println(str1);
byte[] byte2 = str.getBytes("gbk");
for(byte bt : byte2){
System.out.print(Integer.toHexString(bt & 0xff) + " ");
}
System.out.println();
String str2 = new String(byte2);
System.out.println(str2);
byte[] byte3 = str.getBytes("utf-8");
for(byte bt : byte3){
System.out.print(Integer.toHexString(bt & 0xff) + " ");
}
System.out.println();
String str3 = new String(byte3, "utf-8");
System.out.println(str3);
byte[] byte4 = str.getBytes("utf-16be");
for(byte bt : byte4){
System.out.print(Integer.toHexString(bt & 0xff) + " ");
}
System.out.println();
String str4 = new String(byte4, "utf-16be");
System.out.println(str4);
}
}