首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2SE开发 >

用JEditorPane显示rtf文档,有中文时出现乱码,求教。该如何解决

2012-01-30 
用JEditorPane显示rtf文档,有中文时出现乱码,求教。如题:用word新建一个空文档,输入一排英中文混排的文字,

用JEditorPane显示rtf文档,有中文时出现乱码,求教。
如题:
用word新建一个空文档,输入一排英中文混排的文字,另存为rtf文件:c:\test.rtf。


JEditorPane   jEditorPane1   =   new   JEditorPane();  
jEditorPane1.setContentType( "text/rtf ");  
File   file   =   new   File   ( "c:/test.rtf ");
String   str   =   file.getAbsolutePath();
str   =   "file: "+str;
jEditorPane1.setPage(str);
jEditorPane1.setEditable(false);
JFrame   jframe   =   new   JFrame( "test ");
jframe.setContentPane(jEditorPane1);
jframe.setBounds(0,0,100,100);
jframe.setVisible(true);

显示出来的英文字符正确,中文乱码。

[解决办法]
出现乱码啊,应该是字符集的问题.你设置一下encode,比如设置成utf-8
[解决办法]
你试过其他的字符集没?除了gb2312之外的
[解决办法]
this.richTextBox1.Rtf = @ "{\rtf1\ansi\ansicpg936 dajiahao: 13:11:40 "+ @ "\par 文章 } ";

这个rtf可以正常显示中文
[解决办法]
936 在这里代表rtf的简体中文字符集

热点排行