Character Encoding conversion

Hi,

How can we convert UTF-8 format to UCS-2.

Urgent.

[72 byte] By [sanu018a] at [2007-11-27 10:13:00]
# 1

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.

sabre150a at 2007-7-28 15:24:04 > top of Java-index,Java Essentials,Java Programming...
# 2

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.

malcolmmca at 2007-7-28 15:24:04 > top of Java-index,Java Essentials,Java Programming...