• Culturally dependent information in some documents is handled through a mechanism called character encoding. Character encoding is an unambiguous mapping of the members of a character set (letters, ideographs, digits, symbols, or control functions) to specific numeric code values. It represents the way the file is stored. Example character encodings are ISO-8859-1, ISO-8859-5, Shift-jis, Euc-jp, and UTF-8. When the file is passed to an user agent (JEditorPane) it is converted to the document character set (ISO-10646 aka Unicode).

    There are multiple ways to get a character set mapping to happen with JEditorPane.

    1. One way is to specify the character set as a parameter of the MIME type. This will be established by a call to the setContentType method. If the content is loaded by thesetPage method the content type will have been set according to the specification of the URL. It the file is loaded directly, the content type would be expected to have been set prior to loading.
    2. Another way the character set can be specified is in the document itself. This requires reading the document prior to determining the character set that is desired. To handle this, it is expected that the EditorKit.read operation throw a ChangedCharSetException which will be caught. The read is then restarted with a new Reader that uses the character set specified in the ChangedCharSetException (which is an IOException).
  • setContentType

    public final void setContentType(String type)
    Sets the type of content that this editor handles. This calls getEditorKitForContentType, and then setEditorKit if an editor kit can be successfully located. This is mostly convenience method that can be used as an alternative to calling setEditorKit directly.

    If there is a charset definition specified as a parameter of the content type specification, it will be used when loading input streams using the associated EditorKit. For example if the type is specified as text/html; charset=EUC-JP the content will be loaded using the EditorKit registered for text/html and the Reader provided to theEditorKit to load unicode into the document will use the EUC-JP charset for translating to unicode. If the type is not recognized, the content will be loaded using theEditorKit registered for plain text, text/plain.

    Parameters:
    type - the non-null mime type for the content editing support
    Throws:
    NullPointerException - if the type parameter is null
    See Also:
    getContentType()
    所以总之就是调用setContentType("text/html;charset=utf-8");即可。
     

JEditorPane中html文档中文乱码解决的更多相关文章

  1. 解决Asp.net Core中chtml文档中文乱码的问题

    原因 由于Visual Studio 2017在保存chtml时,文本格式非utf-8,所以导致中文会出现乱码情况. 解决办法 在工具->扩展与更新中添加插件"ForceUTF8 (w ...

  2. sublime text3 中 python3编译出现中文乱码解决方法

    转 https://blog.csdn.net/Bin_bin_bingo/article/details/80531582 一.乱码现象 利用sublime自带编译快捷方式ctrl+B会出现中文乱码 ...

  3. Linux中文件/文本的中文乱码解决方法

    Linux显示在Windows编辑过的中文就会显示乱码是由于两个操作系统使用的编码不同所致.Linux下使用的编码是utf8,而Windows使用的是gb18030.因此,解决Linux打开txt/c ...

  4. linux中使用unzip命令中文乱码解决办法

    今天在使用unzip进行解压缩文件时,发现解压出的文件中文乱码,最后使用如下命令解决: unzip -O CP936 xxx.zip 特此记录一下.

  5. url中向后台传递中文乱码解决方法

    方法一: 1.jsp中代码 var userNo = $('#prisoner_id').val();      userNo = encodeURI(userNo);      allPrisone ...

  6. 【转】IDEA 中配置文件properties文件中文乱码解决

    1.首先我们的IDEA文件编码一般都修改为utf-8(setting-->file encodings--->Global Encoding 和 Project Encoding 都设置为 ...

  7. 手机打开PDF文档中文英文支持(乱码问题)解决攻略

    电子书的优点很多,随时随地阅读,无论白天黑夜走路坐车都能阅读:想确认一下某句话是不是这本书里的,搜索一下就可以知道:搬家也不用发愁,几万本书带在身上,依然轻松步行.我买了一台平板主要动因就是为了看书, ...

  8. Linux系统下Java 转换Word到PDF时,结果文档内容乱码的解决方法

    本文分享在Linux系统下,通过Java 程序代码将Word转为PDF文档时,结果文档内容出现乱码该如何解决.具体可参考如下内容: 1.问题出现的背景 在Windows系统中,使用Spire.Doc ...

  9. Atom打开txt文件中文乱码解决、指定文件的语法格式、win10中禁止睡眠

    1.Atom中文乱码解决 首先保证打开的txt文件的编码格式为UTF-8无BOM编码格式,可以使用Notepad++更改,如下图所示: 然后再在atom中打开文件,并右键点击文件内容的任意位置,Cha ...

随机推荐

  1. Java & XML Tutorial

    Java comes with a set of tools to process XML. These Java XML tools are: SAX Parser StAX Parser DOM ...

  2. CP2102模块介绍(USB转uart)

    1.主芯片为CP2102,安装驱动后生成虚拟串口2.USB取电,引出接口包括3.3V(<40mA),5V,GND,TX,RX,信号脚电平为3.3V,正逻辑3.板载状态指示灯.收发指示灯,正确安装 ...

  3. HDU 4628

    这是一个大水题啊... 因为比赛时不会算复杂度耽误半天. i从0到2^n枚举集合i的所有分割两半的情况的复杂度为O(3^n),可以想象这个过程相当于是给每个位标记0,1,2(0表示不选,1,2表示两个 ...

  4. Windows下环境变量配置

    JAVA_HOME=C:\Program Files\Java\jdk1.6.0_33   PATH+=%JAVA_HOME%\bin;   CLASSPATH=.;%JAVA_HOME%\lib\d ...

  5. 解决eclipse 使用run运行,始终会跳到debug模式!

    查看此选项是否选择中卫always,若是,更改为never或prompt,重启eclipse即可

  6. struts中的helloword(1)

    注:文章中的所有图片均在附件中明白表明   首先要安装jdk1.6以及tomcat6和myeclipse 对于这些配置的安装 这里不再细细说明  其次是下载struts2  第一步:去struts21 ...

  7. WdatePicker开始日期不能大于结束日期

    <input class="input_calendar inputcss" id="startDate" runat="server" ...

  8. 如何使得VIM显示行号

    如何使得VIM显示行号: :set number

  9. 手机端overflow scroll卡顿的情况

    在容器里设置或者html,body{-webkit-overflow-scrolling: touch;}

  10. powershell 查看程序的tcp网络连接

    在运维工作中,常常查看某个业务的网络连接状况,在这里借用netstat来实现查找连接.用hash特性避免反复. $add=@{} while(1){ ps|?{$_.path -match 'E:\\ ...