JEditorPane中html文档中文乱码解决
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.- One way is to specify the character set as a parameter of the MIME type. This will be established by a call to the
setContentTypemethod. If the content is loaded by thesetPagemethod 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. - 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 aChangedCharSetExceptionwhich will be caught. The read is then restarted with a new Reader that uses the character set specified in theChangedCharSetException(which is anIOException).
- 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
public final void setContentType(String type)
Sets the type of content that this editor handles. This callsgetEditorKitForContentType, and thensetEditorKitif an editor kit can be successfully located. This is mostly convenience method that can be used as an alternative to callingsetEditorKitdirectly.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 astext/html; charset=EUC-JPthe content will be loaded using theEditorKitregistered fortext/htmland the Reader provided to theEditorKitto load unicode into the document will use theEUC-JPcharset for translating to unicode. If the type is not recognized, the content will be loaded using theEditorKitregistered for plain text,text/plain.- Parameters:
type- the non-nullmime type for the content editing support- Throws:
NullPointerException- if thetypeparameter isnull- See Also:
getContentType()- 所以总之就是调用setContentType("text/html;charset=utf-8");即可。
JEditorPane中html文档中文乱码解决的更多相关文章
- 解决Asp.net Core中chtml文档中文乱码的问题
原因 由于Visual Studio 2017在保存chtml时,文本格式非utf-8,所以导致中文会出现乱码情况. 解决办法 在工具->扩展与更新中添加插件"ForceUTF8 (w ...
- sublime text3 中 python3编译出现中文乱码解决方法
转 https://blog.csdn.net/Bin_bin_bingo/article/details/80531582 一.乱码现象 利用sublime自带编译快捷方式ctrl+B会出现中文乱码 ...
- Linux中文件/文本的中文乱码解决方法
Linux显示在Windows编辑过的中文就会显示乱码是由于两个操作系统使用的编码不同所致.Linux下使用的编码是utf8,而Windows使用的是gb18030.因此,解决Linux打开txt/c ...
- linux中使用unzip命令中文乱码解决办法
今天在使用unzip进行解压缩文件时,发现解压出的文件中文乱码,最后使用如下命令解决: unzip -O CP936 xxx.zip 特此记录一下.
- url中向后台传递中文乱码解决方法
方法一: 1.jsp中代码 var userNo = $('#prisoner_id').val(); userNo = encodeURI(userNo); allPrisone ...
- 【转】IDEA 中配置文件properties文件中文乱码解决
1.首先我们的IDEA文件编码一般都修改为utf-8(setting-->file encodings--->Global Encoding 和 Project Encoding 都设置为 ...
- 手机打开PDF文档中文英文支持(乱码问题)解决攻略
电子书的优点很多,随时随地阅读,无论白天黑夜走路坐车都能阅读:想确认一下某句话是不是这本书里的,搜索一下就可以知道:搬家也不用发愁,几万本书带在身上,依然轻松步行.我买了一台平板主要动因就是为了看书, ...
- Linux系统下Java 转换Word到PDF时,结果文档内容乱码的解决方法
本文分享在Linux系统下,通过Java 程序代码将Word转为PDF文档时,结果文档内容出现乱码该如何解决.具体可参考如下内容: 1.问题出现的背景 在Windows系统中,使用Spire.Doc ...
- Atom打开txt文件中文乱码解决、指定文件的语法格式、win10中禁止睡眠
1.Atom中文乱码解决 首先保证打开的txt文件的编码格式为UTF-8无BOM编码格式,可以使用Notepad++更改,如下图所示: 然后再在atom中打开文件,并右键点击文件内容的任意位置,Cha ...
随机推荐
- Java数组的内存管理
Java数组的内存管理 Java语言是典型的静态语言,因此Java的数组是静态的,即当数组被初始化之后,该数组的长度是不可变的.Java程序中的数组必须经初始化才能使用.所谓初始化,就是当数组对象的元 ...
- Quartus II调用modelsim无缝仿真
本篇文章为转载,写的不错,最近在学modelsim仿真,网上的教程很乱,把自己认为不错的整理贴出来,后面有机会会写个详细点的. Quartus 中调用modelsim的流程 1. 设定仿真工具 ass ...
- java中几个特殊的类
1 内部类-----是在其他类中的类 1.1 内部类的定义 将类定义为 class xxxx{... ...}置于某个类的内部即可‘ 内部类编译时生成 xxxx$xxxx的class文件 内部类不能够 ...
- 写一个函数reverseList,该函数能够接受一个List,然后把该List 倒序排列。 例如: List list = new ArrayList(); list.add(“Hello”); list.add(“World”); list.add(“Learn”); //此时list 为Hello World Learn reverseList
package homework004; import java.util.ArrayList; import java.util.List; public class Daoxu { public ...
- svn 如何解决冲突
项目中,往往不止你一人开发,多人开发,难免会有代码的冲突.彼此间谁也不能保证不会修改同个文件.如果修改了同个方法的内容.这时提交到svn是会提示代码冲突的. 当然,冲突是可控的,但不能避免.每次写代码 ...
- cas 3.5.2 登录成功后,如何返回用户更多信息?
国内私募机构九鼎控股打造APP,来就送 20元现金领取地址:http://jdb.jiudingcapital.com/phone.html内部邀请码:C8E245J (不写邀请码,没有现金送)国内私 ...
- hdu 5465 Clarke and puzzle 二维线段树
Clarke and puzzle Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/showproblem.php? ...
- delphi 连接mysql
Delphi连接MySQL真麻烦,研究了一天,从网上找了无数文章,下载了无数插件都没解决.最后返璞归真,老老实实用ADO来连接,发现也不是很顺利,但最终还是连接成功了.多少有点心得:ADO各个组件的作 ...
- 使用RecyclerView写树形结构的TreeRecyclerView
简单介绍 android是不提供树形控件的,假设须要使用树形控件.我们应该怎么做呢? 先看效果 上图是一个明显的树形结构 实现原理 在逻辑上,它们是包括关系.数据结构上是多叉树,这是毋庸置疑的. 可是 ...
- 图片轮换cycle插件的运用
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...