解决读取.properties 中文乱码的问题

如有文件:user.properties

首先执行  native2ascii -reverse -encoding gb2312 user.properties user3.properties

执行命令后,会生成user_zh_CN.properties  文件

然后再执行:

native2ascii user3.properties user_zh_CN.properties

然后你的程序读user_zh_CN.properties的内容就可以。

user_zh_CN.properties 内容如下:

test=\u6d4b\u8bd5\u4e2d\u6587\u4e71\u7801\u95ee\u9898
\u9ad8\u6c5f\u840d
test2=\u5317\u4eac
pay.merName=\u5317\u4eac\u94f6\u5546\u9884\u6388\u6743

 

 

 

测试程序:

 


import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public class Test {

 public static void main(String[] args) {
  System.out.println("=================");
  
  InputStream in;
  try {
   in = new FileInputStream("E:/log/user3.properties");
   Properties property = new Properties();
   property.load(in);
   String username = property.getProperty("test");
   String password = property.getProperty("test2");
   String password2 = property.getProperty("pay.merName");
   System.out.println(username +"--"+password+"-"+password2);
  } catch (FileNotFoundException e) {
   e.printStackTrace();
  }catch (IOException e) {
   e.printStackTrace();
  }

 }

}

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值