- import java.util.PropertyResourceBundle;
- import java.util.ResourceBundle;
- import org.apache.log4j.Logger;
- public class FileBasedProperties implements Properties {
- private static final Logger LOGGER = Logger.getLogger(FileBasedProperties.class);
- private ResourceBundle properties;
- private String filename;
- public FileBasedProperties() {
- }
- public FileBasedProperties(String basename) {
- this.filename = basename;
- properties = PropertyResourceBundle.getBundle(basename);
- }
- public String get(String key) {
- return properties.getString(key);
- }
- public String get(String key, String defaultValue) {
- try {
- String property = properties.getString(key);
- if (property != null) {
- return property;
- }
- } catch (RuntimeException e) {
- LOGGER.warn("Can't load " + key + " from the property file <" + filename + ">, use the default value: " + defaultValue);
- }
- return defaultValue;
- }
- }
读取properties文件-PropertyResourceBundle
最新推荐文章于 2023-07-10 21:41:45 发布