Posts Tagged ‘Platform encoding’
Obtaining the default charset (aka platform encoding) in JAVA
Monday, November 9th, 2009
Posted in: Charset, Platform encoding java, open source.
… is really simple since JDK 1.5:
java.nio.charset.Charset.defaultCharset()
So please don’t use messy, old workarounds such as this:
byte [] byteArray = {'a'};
InputStream inputStream = new ByteArrayInputStream(byteArray);
InputStreamReader reader = new InputStreamReader(inputStream);
String defaultEncoding = reader.getEncoding();
Which, unfortunately, is one of the first things you stumble upon when searching for this topic.
No Comments