parseproperties.java

来自「信息发布 发布系统 动态的菜单 和 信息统计」· Java 代码 · 共 59 行

JAVA
59
字号
/**
 * 
 */
package com.xuntian.material.util;

import java.util.Enumeration;
import java.util.Properties;
import java.util.ResourceBundle;

/**
 * @author lip Mar 7, 2006 copyright@xuntian
 */
public class ParseProperties {
    /**
     * file to properties
     */
    private Properties properties;

    /**
     * 构造函数传递filename
     * 
     * @param fileName
     */
    public ParseProperties(String fileName) {
        ResourceBundle config = ResourceBundle.getBundle(fileName);
        Enumeration<String> keys = config.getKeys();

        this.properties = new Properties();
        while (keys.hasMoreElements()) {
            String key = keys.nextElement();
            this.properties.put(key, config.getString(key));
        }
    }

    /**
     * @param key
     * @return the int value of the key
     */
    public int getInt(String key) {
        String temp = this.getString(key);
        int value = 0;
        if (temp.matches("[0-9]{1,10}")) {
            value = Integer.parseInt(temp);
        } else {
            LogUtil.getLogger(this).error(
                    "DBConfig file:wrong values of the properties: " + temp);
        }
        return value;
    }

    /**
     * @param key
     * @return the string value
     */
    public String getString(String key) {
        return this.properties.getProperty(key);
    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?