I am trying to convert a string encoded in java in UTF-8 to ISO-8859-1. Say for example, in the string 'âabcd' 'â' is represented in ISO-8859-1 as E2. In UTF-8 it is represented as two bytes. C3 A2 I believe. When I do a getbytes(encoding) and then create a new string with the bytes in ISO-8859-1 encoding, I get a two different chars. â. Is there any other way to do this so as to keep the character the same i.e. âabcd?
Java – Converting UTF-8 to ISO-8859-1 in Java – how to keep it as single byte
iso-8859-1javautf-8
Related Question
- Java – How to call one constructor from another in Java
- Java – How to read / convert an InputStream into a String in Java
- Java – How to generate random integers within a specific range in Java
- Java – How to convert between ISO-8859-1 and UTF-8 in Java
- Java – How to determine whether an array contains a particular value in Java
- Java – How to convert a String to an int in Java
- Java – How to create a memory leak in Java
Best Solution
If you're dealing with character encodings other than UTF-16, you shouldn't be using
java.lang.String
or thechar
primitive -- you should only be usingbyte[]
arrays orByteBuffer
objects. Then, you can usejava.nio.charset.Charset
to convert between encodings: