Display Hindi language in console using Java

前端 未结 2 1540
孤独总比滥情好
孤独总比滥情好 2020-12-20 23:13
StringBuffer contents=new StringBuffer();
BufferedReader input =  new BufferedReader(new FileReader(\"/home/xyz/abc.txt\"));
String line = null; //not declared withi         


        
2条回答
  •  离开以前
    2020-12-20 23:36

    You should store the contents in the file as UTF-8 encoded Hindi characters. For instance, in your case it would be अभी समय है जनता जो चाहती है. That is, instead of saving unicode escapes, directly save the raw Hindi characters. You can then simply read like normal.

    You just have to make sure that the editor you use saves it using UTF-8 encoding. See Spanish language chars are not displayed properly?

    Otherwise, you'll have to make the file a .properties file and read using java.util.Properties as it offers unicode unescaping support inherently.

    Also read Reading unicode character in java

提交回复
热议问题