Quantcast
Channel: 海边拾贝 » Java
Viewing all articles
Browse latest Browse all 10

Java处理UTF-8/UNICODE等字符编码格式的文本文件

$
0
0

在中文Windows平台下,Java读取文本文件是以ANSI编码的,这样在打开utf-8编码的中文文件时会乱码,解决方案参考以下文章:

搜斧SearchFull – Java读取UTF-8/UNICODE等字符编码格式的文本文件

其核心为InputStreamReader 类,它负责Java输入中的编码转换。JDK里对其说明为:“It reads bytes and decodes them into characters using a specified charset.”

在遇到输入中文乱码问题的时候,只需要把它套在原有的Reader里,设置好输入源的编码即可正确输入。


Viewing all articles
Browse latest Browse all 10

Trending Articles