1.遇到的第一个问题,写入properties的中文出现乱码的情况
解决的办法:window-->perferences-->General(常规设置)-->content types-->Text-->java properties file
设置为utf-8,点击update后,再创建properties即可
2.当使用inputStream读取时
public Map<String, String> proRead(String proName){
Properties pro = new Properties();
Map<String, String> mpro = new HashMap<String, String>();
InputStream is=getClass().getResourceAsStream(proName);
try {
pro.load(is);
@SuppressWarnings("rawtypes")
Enumeration en=pro.propertyNames();
while (en.hasMoreElements()) {
String key=(String) en.nextElement();
String value=pro.getProperty(key);
mpro.put(key, value);
}
return mpro;
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
结果:
尝试了很多的方法,最后选择使用第三种
3.使用InputStreamReader来进行读取
可以完美的解决乱码的问题