Using supplementary Unicode characters
I want to use unicode characters with codepoints greater than U+FFFF in the java code. So, wrote a small code to check the same:
-
int cp = 0x10177;
char[] ch = new char[2];
ch = Character.toChars(cp);
int low = ch[0];
int high = ch[1];
String st = new String(ch);
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream("krishna.xml"), "UTF-8"));
out.write("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>");
out.write("<krishna>");
out.write(st);
out.write("</krishna>");
out.close();
-
But, when I open the xml in browser, the character is not displayed properly.
However the code works for the case where the code point is less than 0XFFFF(Here, I create the String using another constructor which takes an
int[], offset, length). In this case, the xml has the proper character. So, is
the above way of dealing with supplementary characters correct? If wrong,
what is the correct way to handle supplementary characters in the code?
Thanks,
Krishna.

