当我从 netbeans 运行我的程序时,Unicode 看起来很好。但是当我从编译的 jar 运行它时,它无法正确显示。
以下尝试未能解决该问题
Font font = new Font("Arial Unicode MS", Font.PLAIN, 16);
textarea.setFont(font);
// the two lines above were my attempt to fix the display, no luck
textarea.read( new FileReader( file.getAbsolutePath() ), null );
这是输入文本:
この文の长さは、Twitterの中で许容されるべきである。この文は长すぎない。この文はならず长すぎます。
这是我从 jar 版本启动的程序加载该字符串时的结果:
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' ¸ÐµÐðлеÐðѸÐв Twitter。
最佳答案
不确定,但您应该尝试使用另一个 Reader
来指定另一个字符集。
Charset charset = Charset.forName("UTF-8");
BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(file), charset));
textarea.read( reader , null );
关于java - Unicode JTextArea 从 jar 中显示错误;在netbeans中很好,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24099921/