How to define a new Charset in Java/Android?

I would like to add some more to the answer by @Joachim.

A sample of a custom charset is contained in the book Java NIO by Ron Hitchens. You can download sample of Charset and CharsetProvider from the support site. Note that you have to make a file META-INF/services/java.nio.charset.spi.CharsetProvider that contains the FQCN of the additional CharsetProvider and put it into the jar you will make.


You can add your own Charset implementation by writing a CharsetProvider and registering it via the service discovery mechanism.

You'll need to extend Charset and implements its newDecoder and newEncoder methods to return an appropriate CharsetDecoder and CharsetEncoder respectively.