Do you have any idea why getEncoding() method giving me UTF8 instead of UTF-8?
I don't. The
java.nio.charset.Charset javadocs make it clear which charsets need to be supported. I did a quick grep through the
Java source code, and it looks like
some parts of it may accept "UTF8" instead of "UTF-8" (the XML parser, for example, although that may be required by the XML spec), but not all of it. And in particular, probably not the java.io package.