Reading unicode character in java

后端 未结 7 845
滥情空心
滥情空心 2020-12-05 22:42

I\'m a bit new to java, When I assign a unicode string to

  String str = \"\\u0142o\\u017Cy\\u0142\";
  System.out.println(str);

  final StringBuilder stri         


        
7条回答
  •  粉色の甜心
    2020-12-05 23:02

    Your code should be correct, but I guess that the file "a.txt" does not contain the Unicode characters encoded with UTF-8, but the escaped string "\u0142o\u017Cy\u0142".

    Please check if the text file is correct, using an UTF-8 aware editor such as recent versions of Notepad or Notepad++ on Windows. Or edit it with your favorite hex editor - it should not contain backslashes.

    I tried it with "€" as UTF-8-encoded content of the file and it gets printed correctly. Note that not all Unicode characters can be printed, depending on your terminal encoding (really a hassle on Windows) and font.

提交回复
热议问题