⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 parseproperties.java

📁 信息发布 发布系统 动态的菜单 和 信息统计
💻 JAVA
字号:
/**
 * 
 */
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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -