/**
* Reads a property list (key and element pairs) from the input byte stream.
* The input stream is in a simple line-oriented format and is assumed to use the ISO 8859-1 character encoding;
* that is each byte is one Latin1 character.
* Characters not in Latin1, and certain special characters,
* are represented in keys and elements using Unicode escapes as defined in
* section 3.3 of <cite>The Java Language Specification</cite>.
* The specified stream remains open after this method returns.
*/

load(InputStream inStream)

以上我们注意到一下几点:

1. 从byte流中读取键值对

2. 流应该是规范的properties文件,流被假定为ISO 8859-1 字符编码(即流编码为gbk时会产生乱码)

3. 1byte对应8bit,即二进制 1111 1111 ,表示范围是十六进制 00-FF

4. 默认字符之外的字符应该使用Unicode 逃脱(eclipse properties 自带该功能),例如:小明 → \u5c0f\u660e

5. 该方法执行完毕后,流依旧开着,需要调用close 将流关闭

/**
* Reads a property list (key and element pairs) from the input character stream in a simple line-oriented format.
*/

load(Reader reader)

以上我们注意到以下几点:

1. 从character流中读取键值对

2. 流应该是规范的properties文件

3. input character stream 是可以读取中文的

乱码解决方案一:

using Unicode escapes

乱码解决方案二:

将InputStream 转换成 Reader

import java.io.InputStreamReader;
properties.load(new InputStreamReader(in));

properties.load(in); 引出的中文乱码问题的更多相关文章

  1. Java读写.properties文件实例,解决中文乱码问题

    package com.lxk.propertyFileTest; import java.io.*; import java.util.Properties; /** * 读写properties文 ...

  2. springMVC 校验时,CustomValidationMessages.properties中的错误提示信息的中文乱码 问题

    今天在学习springmvc的校验时,遇到了CustomValidationMessages.properties配置文件的信息,才错误提示时是乱码的问题:在网上找了很多方法都没解决:最后原来是在配置 ...

  3. eclipse中文乱码

    问题描述: 在导入log4j.properties文件时里面出现中文乱码,如下: ### 设置### log4j.rootLogger = debug,stdout,D,E ### è¾“å‡ ...

  4. 关于java.util.Properties读取中文乱码的正确解决方案(不要再用native2ascii.exe了)

    从Spring框架流行后,几乎根本不用自己写解析配置文件的代码了,但近日一个基础项目(实在是太基础,不能用硕大繁琐的Spring), 碰到了用java.util.Properties读取中文内容(UT ...

  5. properties文件中中文不能显示或者中文乱码

    1.properties 文件中文乱码问题 鼠标“右击”文件 => Resource => Text file encoding => UTF-8 2.properties 文件解析 ...

  6. 解决Eclipse中.properties文件中文乱码问题

    在.properties文件写注释时,发现中文乱码了,由于之前在idea中有见设置.properties文件的编码类型,便找了找乱码原因 在中文操作系统中,Eclipse中的Java类型文件的编码的默 ...

  7. 读取Properties文件以及中文乱码问题

    在java类中常见的读取Properties文件方式,是使用Properties.load(inputStream);的方式但是常常出现中文乱码问题,这就很尴尬了 public synchronize ...

  8. SpringMVC+HibernateValidator,配置在properties文件中的错误信息回显前端页面出现中文乱码

    问题: 后台在springMVC中使用hibernate-validator做参数校验的时候(validator具体使用方法见GOOGLE),用properties文件配置了校验失败的错误信息.发现回 ...

  9. Eclipse中 properties 文件中 中文乱码

    在.properties文件写注释时,发现中文乱码了,由于之前在idea中有见设置.properties文件的编码类型,便找了找乱码原因 在中文操作系统中,Eclipse中的Java类型文件的编码的默 ...

随机推荐

  1. linux的chmod与chown命令详解

    使用方式 : chmod [-cfvR] [--help] [--version] mode file... 说明 : Linux/Unix 的档案存取权限分为三级 : 档案拥有者.群组.其他.利用  ...

  2. I.MX6 show battery states in commandLine

    #/bin/sh # I.MX6 show battery states in commandLine # 声明: # 在命令行下自动显示电池状态的信息. # # -- # set battery r ...

  3. UVA 550 Multiplying by Rotation (简单递推)

    题意:有些数字是可以这样的:abcd*k=dabc,例如179487 * 4 = 717948,仅仅将尾数7移动到前面,其他都不用改变位置及大小.这里会给出3个数字b.d.k,分别代表b进制.尾数.第 ...

  4. apache开源项目 -- Wicket

    [infoq] Apache Wicket是一个功能强大.基于组件的轻量级Web应用框架,能将展现和业务逻辑很好地分离开来.你能用它创建易于测试.调试和支持的高质量Web 2.0应用.假设其他团队交付 ...

  5. poj 1780 Code

    //题目描述:KEY公司开发出一种新的保险箱.要打开保险箱,不需要钥匙,但需要输入一个正确的.由n位数字组成的编码.这种保险箱有几种类型,从给小孩子玩的玩具(2位数字编码)到军用型的保险箱(6位数字编 ...

  6. Mybatis学习——一对一关联表查询

    1.SQL语句建表 CREATE TABLE teacher( t_id ) ); CREATE TABLE class( c_id ), teacher_id INT ); ALTER TABLE ...

  7. VS2013密匙

    在网上找到的,亲测有用: BWG7X-J98B3-W34RT-33B3R-JVYW9

  8. VS2010使用EventHandler发邮件

    转:http://blog.csdn.net/alfred_72/article/details/9980279 因为不知道VS2010 Sharepoint 有EventReciver这个添加项,走 ...

  9. android电池信息简介

    <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android=&quo ...

  10. 分享一个Web弹框类

    using System; using System.Text; namespace Core { /// <summary> /// MessageBox 的摘要说明. /// < ...