package wordcount1;
import java.io.UnsupportedEncodingException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class demo
{
public static void main(String[] args)
{
String a="哈哈";
try {
byte[] aa = a.getBytes("GB2312");//a的内容用 GB2312进行编码存于aa数组中
byte[] ab = a.getBytes("UTF-8");//a的内容用 UTF-8进行编码存于aa数组中
for (int i = 0; i < aa.length; i++) {
System.out.print(aa[i]);
}
System.out.println();
for (int i = 0; i < ab.length; i++) {
System.out.print(ab[i]);
}
System.out.println();
System.out.println(new String(aa));
System.out.println(new String(ab, "UTF-8"));
System.out.println(new String(aa, "UTF-8"));
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
import java.io.UnsupportedEncodingException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class demo
{
public static void main(String[] args)
{
String a="哈哈";
try {
byte[] aa = a.getBytes("GB2312");//a的内容用 GB2312进行编码存于aa数组中
byte[] ab = a.getBytes("UTF-8");//a的内容用 UTF-8进行编码存于aa数组中
for (int i = 0; i < aa.length; i++) {
System.out.print(aa[i]);
}
System.out.println();
for (int i = 0; i < ab.length; i++) {
System.out.print(ab[i]);
}
System.out.println();
System.out.println(new String(aa));
System.out.println(new String(ab, "UTF-8"));
System.out.println(new String(aa, "UTF-8"));
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
输出:
-71-2-71-2
-27-109-120-27-109-120
哈哈
哈哈
????
}