File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes Are the code pages in charsets.jar documented somewhere? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Are the code pages in charsets.jar documented somewhere?" Watch "Are the code pages in charsets.jar documented somewhere?" New topic
Author

Are the code pages in charsets.jar documented somewhere?

Tom Katz
Ranch Hand

Joined: Aug 19, 2002
Posts: 169
I need to convert raw bytes into various code pages. I tried using the String constructor that takes in a byte[] and a string representing the code page - e.g 'new String(bytes, "cp037") - and it seemed like some of the characters I got back were different from what's documented for that code page.
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
Hmmm - no offense, but that sounds kind of backwards. The new String(byte[], String) constructor does convert to different encodings - it converts from different encodings of bytes, to a statndard Java String consisting of a sequence of chars whose numeric values are interpreted as Unicode. Strings do not have encodings; bytes have encodings. So if you've got an array of bytes, you need to find out what one encoding was used to generate the bytes in the array. Then you can use that encoding in the new String(byte[], String) constructor to get a String. If you then wish to convert that String to bytes, using some other encoding, then you can use getBytes(String) - naming whatever encoding you want.


"I'm not back." - Bill Harding, Twister
Tom Katz
Ranch Hand

Joined: Aug 19, 2002
Posts: 169
Thanks for info, I appreciate it...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Are the code pages in charsets.jar documented somewhere?