Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Netbeans console does not display Bangla unicode characters

Tags:

java

I have a test.txt file with some Bengali character written as

আমার মাথা, তোমার মাথা

Now when I run this from some packege,

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

public class Test {
    public static void main( String ajaira[] ) throws FileNotFoundException, IOException
    {
        File f = new File("test.txt") ;
        InputStream is = new FileInputStream(f) ;
        BufferedReader br = new BufferedReader( new InputStreamReader(is) );
        System.out.println("Abs path: " + f.getAbsolutePath() ) ;
        String s ;
        while( (s = br.readLine()) !=null )
        {
            System.out.println(s) ;
        }
    }
}

I get some block... well I could not write it. This is the imageenter image description here Could anyone help with this thing...? Thank you.

like image 970
Dewsworld Avatar asked Aug 28 '11 05:08

Dewsworld


2 Answers

You seem to be using Netbeans. The console in Netbeans uses a Monospace font by default, that is incapable of displaying Bangla characters.

You can switch to a different font from the context menu:

Choose Font for Netbeans Console

and then opt for displaying all the characters in the console using a font with the Bangla glyphs (I chose Arial Unicode MS, but you can choose any other Bangla font):

Choose Font in Dialog

This would display the output that you desire:

Display bangla characters

Also, note the importance of the Netbeans project encoding:

Netbeans project encoding

Apparently, the console encoding happens to be the same as the project encoding; attempting to change this by setting the file.encoding System property yields nothing. In this case, all UTF-8 encoded strings will be displayed without issues. However, if your file happens to be encoded with UTF-16BE/LE or any other encoding scheme, then the console will display gibberish/mojibake as it is impossible to change the terminal/console encoding on an as needed basis. In this case, the preferred approach is to store files in the same encoding as the project encoding, so that displaying their contents via System.out will not result in displaying gibberish.

like image 193
Vineet Reynolds Avatar answered Oct 08 '22 17:10

Vineet Reynolds


Font download link: code.google.com

Here is the look to get solved the font problem in netbeans:

like image 36
X-Coder Avatar answered Oct 08 '22 16:10

X-Coder