Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
703 views
in Technique[技术] by (71.8m points)

java - Netbeans console does not display Bangla unicode characters

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...