Java运行时字符编码 file.encoding

2017-02-05 17:30:00
admin
原创 1791
摘要:Java运行时字符编码 file.encoding

一、Java运行时字符编码

public static void printEncoding() {
Map<String, Charset> charsets = Charset.availableCharsets(); 
for (Map.Entry<String, Charset> entry: charsets.entrySet()) {
String key = entry.getKey();
Charset charset = entry.getValue();
if (key.equals("GBK")) {
System.out.println(charset.name());
System.out.println(charset.displayName());
System.out.println(charset.aliases());
} else if (key.equals("UTF-8")) {
System.out.println(charset.name());
System.out.println(charset.displayName());
System.out.println(charset.aliases());
}
}

String encoding1 = System.getProperty("file.encoding");
System.out.println("Encoding: " + encoding1);
String encoding2 = Charset.defaultCharset().name();
System.out.println("Encoding: " + encoding2);
}


windows默认编码:

GBK
GBK
[CP936, windows-936]
UTF-8
UTF-8
[UTF8, unicode-1-1-utf-8]
Encoding: GBK
Encoding: GBK


windows指定编码,-Dfile.encoding=UTF-8:

GBK
GBK
[CP936, windows-936]
UTF-8
UTF-8
[UTF8, unicode-1-1-utf-8]
Encoding: UTF-8
Encoding: UTF-8


linux默认编码:

GBK
GBK
[windows-936, CP936]
UTF-8
UTF-8
[unicode-1-1-utf-8, UTF8]
Encoding: UTF-8
Encoding: UTF-8

发表评论
评论通过审核之后才会显示。