Display Hindi in console using Java

StringBuffer contents=new StringBuffer();
BufferedReader input =  new BufferedReader(new FileReader("/home/xyz/abc.txt"));
String line = null; //not declared within while loop
while (( line = input.readLine()) != null){
    contents.append(line);
}
System.out.println(contents.toString());

File abc.txtcontains

\u0905\u092d\u0940 \u0938\u092e\u092f \u0939\u0948 \u091c\u0928\u0924\u093e \u091c\u094b \u091a\u093e\u0939\u0924\u0940 \u0939\u0948 \u092

I want to talk in Hindi in the console using Java.

if I just print like this String str = "\ u0905 \ u092d \ u0940 \ u0938 \ u092e \ u092f \ u0939 \ u0948 \ u091c \ u0928 \ u0924 \ u093e \ u091c \ u094b \ u091a \ u093e \ u0939 \ u0924 \ u0924 \ u0924 \ u0924 \ u0948 \ u0940 \ "

System.out.println (ul);

then it works fine, but when I try to read from a file, it does not work.

help me.

+5
source share
2 answers

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 configured to display Hindi (the correct fonts, etc.) and the console encoding matches your Java encoding. The Java code above is just bare bones.)

+6

UTF-8 . , अभी समय है जनता जो चाहती है. unicode- . , .

, UTF-8. . ?

a .properties java.util.Properties, Unicode .

java

+5

All Articles