开发者

Netbeans console does not display Bangla unicode characters

开发者 https://www.devze.com 2023-03-31 01:37 出处:网络
I have a test.txt file with some Bengali character written as আমার মাথা, তোমার মাথা

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 jav开发者_JS百科a.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 image

Netbeans console does not display Bangla unicode characters

Could anyone help with this thing...? Thank you.


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:

Netbeans console does not display Bangla unicode characters

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):

Netbeans console does not display Bangla unicode characters

This would display the output that you desire:

Netbeans console does not display Bangla unicode characters

Also, note the importance of the Netbeans project encoding:

Netbeans console does not display Bangla unicode characters

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.


Font download link: code.google.com

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

Netbeans console does not display Bangla unicode characters


Not NetBeans issue but Logger encoding issue. Force Utf8 for Log4j.

It should be default to UTF8 but it wasn't. Forcing log4j to UTF8 solved my issues.

Symptom: Generated log file was also not in utf8 encoding.

Still valid for NetBeans 8 to 12

0

精彩评论

暂无评论...
验证码 换一张
取 消