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
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. - 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 aChangedCharSetException
which 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 thensetEditorKit
if an editor kit can be successfully located. This is mostly convenience method that can be used as an alternative to callingsetEditorKit
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 astext/html; charset=EUC-JP
the content will be loaded using theEditorKit
registered fortext/html
and the Reader provided to theEditorKit
to load unicode into the document will use theEUC-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 thetype
parameter 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 ...
随机推荐
- Android问题-DelphiXE5编义时提示找不到“连接器(arm-linux-androideabi-ld.exe)"
问题现象:DelphiXE5编义时提示找不到“连接器(arm-linux-androideabi-ld.exe)" 问题提示:Checking project dependencies... ...
- Umbraco Form需要引用些客户端dependencies (jquery)
Preparing your frontend In order to work correctly Umbraco Forms needs some client dependencies, bei ...
- Java远程方法调用(RMI)
Java RMI 指的是远程方法调用 (Remote Method Invocation).它是一种机制,能够让在某个 Java 虚拟机上的对象调用另一个 Java 虚拟机中的对象上的方法.可以用此方 ...
- Hibernate的BaseDao辅助类
1.BaseDao接口类,该类封装了一些hibernate操作数据库的一些常用的方法,包括分页查询,使用该类极大的简化了hibernate的开发 BaseDao.java package com.kj ...
- FindWindow使用方法
函数功能:该函数获得一个顶层窗体的句柄,该窗体的类名和窗体名与给定的字符串相匹配.这个函数不查找子窗体.在查找时不区分大写和小写. 函数型:HWND FindWindow(LPCTSTR IpClas ...
- Codeforces Round #320 (Div. 1) [Bayan Thanks-Round] B. "Or" Game 线段树贪心
B. "Or" Game Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/578 ...
- ABAP 常用系统变量
SY-ABCDE 常量,A-Z字母表SY-BATCH 后台的程序运行SY-COLNO:当前选定列的列号SY-CPAGE 列表的当前显示页SY-CUCOL 屏幕,PAI 的水平光标位置SY-CUROW: ...
- 面试题总结之Linux/Shell
Linux Linux cshrc文件作用 Linux如何起进程/查看进程/杀进程 Linux 文件755 代表什么权限 Linux辅助线程 Linux进程间通信方法 pipeline,msgq... ...
- nginx自定义模块编写-实时统计模块--转载
原文:http://www.vimer.cn/2012/05/nginx%E8%87%AA%E5%AE%9A%E4%B9%89%E6%A8%A1%E5%9D%97%E7%BC%96%E5%86%99- ...
- 常用免费的WebServices地址
天气预报Web服务,数据来源于中国气象局 公用事业http://www.webxml.com.cn/WebServices/WeatherWebService.asmx 中国股票行情分时走势预览缩略图 ...