http://msdn.microsoft.com/en-us/goglobal/cc305166 has the list of characters; should no pre-made option work, writing code to iterate through an array translating Unicode characters to bytes suitable for CP866 shouldn't take much time at all.
Any freeware java library to encode from Unicode to CP866?
-
31-05-2022 - |
Question
I'm trying to print to a device which supports CP866 encoding only.
Unfortunately the device from which I'm printing (an Android device) does not support CP866, resulting in "abc".getBytes("CP866")
throwing the UnsupportedEncodingException
.
So, I guess, I have to do Unicode
to CP866
encoding myself. Is there any freeware java library that does that?
Solution 2
OTHER TIPS
According to the Oracle documentation, Cp866 is a supported encoding for Java 7. So either
- you are using an old version of Java that doesn't support Cp866 (e.g. see @Joachim's comment!!!), or
- the Java runtime is not recognizing the name you are using. (The canonical name for the charset is
"Cp866"
not"CP866"
.)
UPDATE - it is unlikely to be the latter. From what I can make out from the source, the charset lookup mechanism used by the standard "provider" is case insensitive.
References:
The class java.nio.charset.Charset
supports both Cp866 and of course Unicode. I guess you could use that with the encode
and decode
methods.
I was needed to encode string with Cp866 in android. You can use java library with made up charset classes. Cp866 among them.
This is the link: http://www.doc.ic.ac.uk/~awl03/cgi-bin/trac.cgi/miro/browser/trunk/gcc/libjava/classpath/gnu/java/nio/charset
If you want extend Charset class and add you private Charset: Java NIO. Chapter 6 Character sets