to read unicode character in java

前端 未结 3 1014
你的背包
你的背包 2021-01-13 02:24

i am trying to read Unicode characters from a text file saved in utf-8 using java my text file is as follows

अ, अदेबानि ,अन, अनसुला, अनसुलि, अनफावरि, अनजालु, अ

3条回答
  •  孤街浪徒
    2021-01-13 03:09

    You are (most likely) reading the text correctly, but when you write it out, you also need to enable UTF-8. Otherwise every character that cannot be printed in your default encoding will be turned into question marks.

    Try writing it to a File instead of System.out (and specify the proper encoding):

    Writer w = new OutputStreamWriter(
       new FileOutputStream("x.txt"), "UTF-8");
    

提交回复
热议问题