packagetest;importjava.io.*;publicclassssa{publicstaticvoidmain(String[]args){//TODOAuto-generatedmethodstubSystem.out.println(System.getProperty("file.encoding"));System...
package test;
import java.io.*;
public class ssa {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println(System.getProperty("file.encoding"));
System.getProperties().put("file.encoding", "UTF-8");
System.out.println(System.getProperty("file.encoding"));
//try {
byte b[] = null;
try {
b = "大家一起来学习java".getBytes("GBK");
} catch (UnsupportedEncodingException e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
}
OutputStream ak = null;
try {
ak = new FileOutputStream(new File("d:\\encoding.txt"));
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try {
ak.write(b);
} catch (IOException e) {
e.printStackTrace();
}
try {
ak.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
发现运行后正常输出“大家一起来学习java”,UTF-8中文不是3字节,而GBK中文是两字节,为什么不会出现中文乱码,java刚开始接触,各种不懂~求大神解答
展开