java Netbeans 控制台不显示孟加拉语 unicode 字符

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7219249/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-30 19:09:25  来源:igfitidea点击:

Netbeans console does not display Bangla unicode characters

java

提问by Dewsworld

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

我有一个 test.txt 文件,其中一些孟加拉语字符写为

???? ????, ????? ????

???? ????, ????? ????

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 hereCould anyone help with this thing...? Thank you.

我有一些障碍...好吧我写不出来。这是图片在此处输入图片说明谁能帮忙解决这个问题...?谢谢你。

回答by Vineet Reynolds

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

您似乎在使用 Netbeans。Netbeans 中的控制台默认使用 Monospace 字体,无法显示孟加拉语字符。

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

您可以从上下文菜单切换到不同的字体:

Choose Font for Netbeans Console

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

然后选择使用带有孟加拉字形的字体在控制台中显示所有字符(我选择了 Arial Unicode MS,但您可以选择任何其他孟加拉字体):

Choose Font in Dialog

Choose Font in Dialog

This would display the output that you desire:

这将显示您想要的输出:

Display bangla characters

Display bangla characters

Also, note the importance of the Netbeans project encoding:

另外,请注意 Netbeans 项目编码的重要性:

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.encodingSystem 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/mojibakeas 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.outwill not result in displaying gibberish.

显然,控制台编码恰好与项目编码相同;试图通过设置file.encodingSystem 属性来改变这一点不会产生任何结果。在这种情况下,所有 UTF-8 编码的字符串都将毫无问题地显示出来。但是,如果您的文件碰巧使用 UTF-16BE/LE 或任何其他编码方案进行编码,则控制台将显示乱码/ mojibake,因为无法根据需要更改终端/控制台编码。在这种情况下,首选的方法是以与项目编码相同的编码存储文件,这样显示它们的内容System.out不会导致显示乱码。

回答by X-Coder

Font download link: code.google.com

字体下载链接:code.google.com

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

这是解决netbeans中字体问题的外观: