Character Encoding conversion
Hi,
How can we convert UTF-8 format to UCS-2.
Urgent.
Hi,
How can we convert UTF-8 format to UCS-2.
Urgent.
Convert the utf-8 bytes to a string using
String s = new String(utf8Bytes, "utf-8");
and then convert to UCS2 bytes using
byte[] ucs2Bytes = s.getBytes("UCS-2");
P.S. Using 'urgent' is considered bad form since it implies that your problem is more important than others.
Depends somewhat on what form the original is in, and what form you want the result.
Typically, open a FileInputStream, then wrap that in an InputStreamReader with the old encoding name. Open a FileOutputStream, likewise with an OutputStreamWriter and the new encoding. Then read characters into a char[] buffer, and copy them to the writer a bufferful at a time.