java.nio.charset.IllegalCharsetNameException: UTF-8

If you get an IllegalCharsetNameException with an obviously correct charset (It also can happen with any ISO charset like ISO-8859-1), you definitely should check if there are any preceding or subsequent characters like a space for example. Also no quotations are allowed, e.g. "UTF-8". 

Exception in thread "main" java.nio.charset.IllegalCharsetNameException: UTF-8 
at java.nio.charset.Charset.checkName(
at java.nio.charset.Charset.lookup2(
at java.nio.charset.Charset.lookup(
at java.nio.charset.Charset.isSupported(

Leave a Comment