Display Hindi language in console using Java

前端 未结 2 1548
孤独总比滥情好
孤独总比滥情好 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:34

    Use Apache Commons Lang.

    import org.apache.commons.lang3.StringEscapeUtils;
    
    // open the file as ASCII, read it into a string, then
    String escapedStr; // = "\u0905\u092d\u0940 \u0938\u092e\u092f \u0939\u0948 ..."
    // (to include such a string in a Java program you would have to double each \)
    
    String hindiStr = StringEscapeUtils.unescapeJava( escapedStr );
    
    System.out.println(hindiStr);
    

    (Make sure your console is set up to display Hindi (correct fonts, etc) and the console's encoding matches your Java encoding. The Java code above is just the bare bones.)

提交回复
热议问题