A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Win a copy of
OCA Java SE 8 Programmer I Study Guide 1Z0-808
this week in the
Java in General
Converting from ISO-8859-1 to UTF-8
Joined: Nov 15, 2002
Aug 24, 2005 22:26:00
How do I convert a
from ISO-8859-1 to UTF-8 encoding?
I tried using the
classes but some special characters like bullets etc are not getting converted properly.
Here is what I have been trying. I hope it makes sense.
byte bytedata = resultset.getBytes("COLUMN_NAME") ; // Comes in ISO form, as the character set in the DB is set to ISO Charset iso = Charset.forName("ISO-8859-1"); CharsetDecoder isodecoder = iso.newDecoder(); ByteBuffer bbuf = ByteBuffer.wrap(bytedata); CharBuffer cbuf = isodecoder.decode(bbuf); // Decode from ISO to UTF-16 Charset utf8 = Charset.forName("UTF-8"); CharsetEncoder utf8encoder = utf8.newEncoder(); ByteBuffer outbuffer = utf8encoder.encode(cbuf); // Encode from UTF-16 to UTF-8 str1 = new String(outbuffer.array(), "UTF-8"); // Resultant String
Will appreciate any thoughts/suggestions on this.
Thanks in advance,
Joined: Aug 10, 2005
Aug 25, 2005 12:34:00
Could you post some code with sample data that shows the problem?
Ie create a string with the problem characters using \uxxxx and then run it thru your code to demonstrate the problem. Print the results and post it.
I agree. Here's the link:
subject: Converting from ISO-8859-1 to UTF-8
Changing charset from UTF-16 to ISO 8859-1
MySQL and reading non-English characters in UTF-8
What is Encoding and character conversion
Read Arabic text in Servlet
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2015