Hi,
Crossposted due to no answers yet in my other thread:
https://stackoverflow.com/questions/...om-inputstream
I keep getting escaped Unicode strings (slash + U) from the InputStream, instead of the correct characters. I found others having the same issue and their problems were solved by specifying UTF-8 in the InputStreamReader constructor:
https://stackoverflow.com/questions/...tream-as-utf-8
https://www.mkyong.com/java/how-to-r...m-a-file-java/
This is not working for me and I don't know why. No matter what I try, I keep getting the escaped unicode values (slash-U + hexadecimal) instead of the actual language characters. What am I doing wrong here? Thanks in advance!
// InputStream is is a FileInputStream: public void load(InputStream is) throws Exception { BufferedReader br = null; try { // Passing "UTF8" or "UTF-8" to this constructor makes no difference for me: br = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8)); String line = null; while ((line = br.readLine()) != null) { // The following prints "got line: chinese = \u4f60\u597d" instead of "got line: chinese = 你好" System.out.println("got line: " + line); } } finally { if (br != null) { br.close(); } } }
If I use a ResourceBundle against the same properties file, that gives me the correct Chinese characters as expected. So I know it's not a font issue, and I'm pretty sure it's not related to the encoding of the properties file. This line:
new InputStreamReader(is, StandardCharsets.UTF_8)
Seems to fix it for everyone else except me. I've also tried various other character sets ("GB2312", "GBK", "BIG5") with no change at all. I think I may be barking up the wrong tree at this point, but I just don't know where else to look for the cause of this. Thanks again!!