dcsimg
convert BIG5 byte[] to UTF8 String ???
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Eric_Chow
Posted On:   Monday, July 29, 2002 07:35 PM

Hello, Would you please to teach me how I can convert a byte array(in BIG5) to UTF8 String? I wrote a simple code that can work very well with file, but if I change as following, it doesn't work, would you please to teach me how to solve it? Best regards, Eric public static String convert(byte[]src, String from, String to) throws Exception { // set up byte streams InputStream in = new ByteArrayInputStream(src); ByteArrayOutputStream out = new ByteArrayOutputStream(); // Set up character stream Reader r = new BufferedReader(new InputStreamReader(in, from)); Writer w = new BufferedWriter(new OutputStreamWriter(out, to));    More>>

			
Hello,

Would you please to teach me how I can convert a byte array(in BIG5) to UTF8 String?

I wrote a simple code that can work very well with file,
but if I change as following, it doesn't work, would you please to teach me how to solve it?

Best regards,
Eric


public static String convert(byte[]src, String from, String to) throws Exception {
// set up byte streams
InputStream in = new ByteArrayInputStream(src);

ByteArrayOutputStream out = new ByteArrayOutputStream();

// Set up character stream
Reader r = new BufferedReader(new InputStreamReader(in, from));
Writer w = new BufferedWriter(new OutputStreamWriter(out, to));

char[] buffer = new char[4096];
int len;

while((len = r.read(buffer)) != -1) {
w.write(buffer, 0, len);
}
r.close();
w.flush();
w.close();
byte[]result = out.toByteArray();


return new String(result);

}

   <<Less
About | Sitemap | Contact