简体   繁体   中英

What if my JRE doesn't support a character encoding?

What if a file is generated using an encoding that my JRE doesn't support? Is there anyway to extend/customize what my JRE can handle?

This might be a terrible/irrelevant example (I'm just brushing up on character sets/encodings for the first time), but I believe the Linux JRE does not handle CP-1252 (a Windows encoding). If that's the case, then how can I get a Java app running on a Linux machine to read a CP-1252-encoded file?

Even if the Linux JRE distro does support CP-1252 (making that a horrible example), I know for a fact that there are encodings that it doesn't support. Whatever those encodings are, is there any way to extend its standard Charactset , and if so, how?

The Java class library has a mechanism for adding new character set support; see the javadocs for CharsetProvider .

The basic idea is that you write a class that implements the CharsetProvider API. Then in your JAR file you add a file called "/META-INF/services/java.nio.charset.spi.CharsetProvider" that lists your charset names, in a prescribed format.

(I also came across this bug report http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4619777 which might affect you if you are trying to add your own Charsets in a trusted applet ...)


Do you know of any "Charset Extension libraries" out there that already do this (and provide lots of non-standard charsets)?

The only example I could find is JCharset and it only adds 8 extra charsets.

If you (or anyone else) needs a charset that is not included, may I suggest that you download JCharset, implement the new charset and then post the changes to the author as patches.

The documentation says:

Support for new charsets can be made available via the interface defined in the CharsetProvider class in the java.nio.charset.spi package.

Follow the link and read the instructions...

sunilkumar from vmoksha

Please check your .xml file containg UTF-8

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM