个人用,主要是保存一段小代码,用于不同字符集配置文件的读取:
//按文件的字符集读取配置文件
public static void readProperties(ServletContext in_servletContext)
{
servletContext = in_servletContext;
String filePath = servletContext.getRealPath("/home/oracle11/conf");
String configFilePath = filePath + "/config.properties";
Properties props = new Properties();
try {
InputStream in=new FileInputStream(configFilePath);
BufferedReader bf=new BufferedReader(new InputStreamReader(in,"UTF-8"));
props.load(bf);
Iterator it = props.keySet().iterator();
while (it.hasNext()) {
String key = (String)it.next();
configMap.put(key, props.get(key));
}
} catch (Exception ex) {
logger.error(ex.getMessage());
}
}
--以上主要是解决一些配置文件中有一些特殊字符的情况,而用常规的方法读出来一般都是乱码的问题。