开发者

Determining default character set of platform in Java

I am programming in Java

I have the code as:

byte[] b = test.getBytes();

In the api it is specified that if we do not specify character encoding it takes the default platform开发者_开发百科 character encoding.

What is meant by "default platform character encoding" ?

Does it mean the Java encoding or the OS encoding ?

If it means OS encoding the how can i check the default character encoding of Windows and Linux ? Is there anyway we can get the default character encoding using command line ?


The system property file.encoding is JVM vendor specific. In this specific case it's only applicable on the Sun JVM and it may not work on JVM's from other vendors than Sun.

Rather use Java SE API provided Charset#defaultCharset().

Charset defaultCharset = Charset.defaultCharset();


It means the default character encoding of the JVM that you're running on,

To check the default encoding you can do the following:

System.getProperty("file.encoding");

that will return the default encoding (and the one used by getBytes() above).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜