java读取全局properties属性文件并解决中文乱码问题 2015-08-19 Java java读取全局properties属性文件并解决中文乱码问题1234567891011121314151617181920212223242526272829303132import org.apache.log4j.Logger;import java.io.BufferedReader;import java.io.IOException;import java.io.InputStream;import java.io.InputStreamReader;import java.util.Properties;public class Config { private static Logger logger = Logger.getLogger(Config.class); public class Key { public static final String SmsPattern = "sms.pattern"; } public Config(){} private static Properties props = new Properties(); static{ try { InputStream inputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream("../config.properties"); BufferedReader bf = new BufferedReader(new InputStreamReader(inputStream)); props.load(bf); logger.info("config load success."); } catch (IOException e) { logger.fatal(e); } } public static String getValue(String key){ return props.getProperty(key); }} 原创作品,允许转载,转载时务必以链接形式标明文章出处、作者信息以及本声明,否则将追究法律责任。https://christopher-ustb.github.io/dev-log/java/java读取全局properties属性文件并解决中文乱码问题/ 赏 Prev Ubuntu git server搭建指南