Reading unicode character in java

后端 未结 7 840
滥情空心
滥情空心 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:05

    Java interprets unicode escapes such as your \u0142 that are in the source code as if you had actually typed that character (latin small letter L with stroke) into the source. Java does not interpret unicode escapes that it reads from a file.

    If you take your String str = "\u0142o\u017Cy\u0142"; and write it to a file a.txt from your Java program, then open the file in an editor, you'll see the characters themselves in the file, not the \uNNNN sequence.

    If you then take your original posted program and read that a.txt file you should see what you expected.

提交回复
热议问题