Is this input straight hex numbers (i.e. '4', 'E' ,'D' ...), or does each represent a Unicode character (i.e '4ED6', '6211'...)?
I take it you need to write this as a Java Unicode escape sequence on the way out, right? (e.g. '\u4ED6').
If this is what you're looking to do, it should just be a matter of tacking the '\u...' on in the right places, and dumping the whole thing out as a string.
If it isn't, I suspect you're confused about how Java deals with Unicode. Basically, once any data is inside a Java program, it's Unicode. All characters are stored in UTF-8 encoding, one of the Unicode standards.
If you are reading in from or writing to a file that needs to be in a particular encoding, Unicode or not, have a look at the constructors for InputStreamReader and OutputStreamWriter that let you define an encoding.
Hope that helps!
Martin Hughes
Yes, I know that java program automatically convert the unicodes for us.
But this is from an com port input where i received this as a string.
Hence, I will have a string of "4ED66211". They are in hexadecimal form. But I will need to write it into the file that show the representation of this as unicode character and not "4ED66211".
Dear sinlanyeo,
I remember that I have answered your question before, isn't it ?
Please refer to http://www.angelfire.com/amiga/yores and download zip file. It contains a function called " public String transferHtmlToJava( String source )" which will convert the W3C representation of unicode to JAVA representation of unicode, e.g. "& # 3 0 0 4 5" -> "\u30045" .
You can modify it to achieve your requirement.
M.T.