我正在努力在JEditorPane中显示阿拉伯语rtf。它显示错误的字符可能是因为它是错误的编码,我不知道如何解决它。如何使* .rtf文件在JContentPane上以UTF-8编码显示?
我可以得到一些帮助吗?这是代码的相关部分。
textPane.setEditorKit(new AdvancedRTFEditorKit());
textPane.setBackground(Color.white);
try {
BufferedReader fi = new BufferedReader(
new InputStreamReader(
new FileInputStream("C:/test - Copy.rtf"), "UTF-8"));
rtf.read(fi, textPane.getDocument(), 0);
System.out.println(textPane.getDocument());
System.out.println(rtf.toString());
}
catch(FileNotFoundException e)
{
System.out.println("File not found");
}
catch(IOException e)
{
System.out.println("I/O error");
}
catch(BadLocationException e)
{
在此先感谢您。
你在哪里定义变量'rtf'? – 2013-03-20 17:36:57
首先用'setContentType(“text/plain”)'(没有EditorKit)显示它。现在你可以看看,文件的编码是UTF-8以及所选字体是否处理阿拉伯文。 – 2013-03-20 17:41:20
rtf被声明为“public static AdvancedRTFEditorKit rtf = new AdvancedRTFEditorKit();” 它实际上是用UTF-8编码的。这似乎不是问题。 – user2191986 2013-03-20 22:49:17