解决读取.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();
  }

 }

}

 

 

你可能感兴趣的:(properties)