… 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.

Tagged with →  
Share →

Leave a Reply

Your email address will not be published. Required fields are marked *