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

📄 propertiesloader.java

📁 办公自动化项目
💻 JAVA
字号:

package hong.javanet.util;
import java.util.*;
import java.io.*;
import org.apache.log4j.Logger;
/**
 *
 * <p>Title: </p>
 *
 * <p>Description: </p>
 *
 * <p>Copyright: Copyright (c) 2006</p>
 *
 * <p>Company: </p>
 *
 * @author 洪桃李
 * @version 2.0
 */
public class PropertiesLoader {
    private static Logger log = Logger.getLogger(PropertiesLoader.class);
    public static Properties load(String resource) {
        Properties result = new Properties();
        Set loadedResources = new HashSet();
        load(resource,loadedResources,result);
        return result;
    }

    private static final String INCLUDE = "include";
    private static void load(String resource,Set loadedResources,Properties result) {
        try {
            Properties pro = new Properties();
            pro.load(PropertiesLoader.class.getClassLoader()
                     .getResourceAsStream(resource));
            loadedResources.add(resource);
            Enumeration enumer = pro.propertyNames();
            while (enumer.hasMoreElements()) {
                String item = (String) enumer.nextElement();
                if (item.startsWith(INCLUDE)) {
                    String include = pro.getProperty(item);
                    if(include!=null && include.trim().length()>0) {
                        if (!loadedResources.contains(include.trim())) {
                            load(include.trim(), loadedResources, result);
                        }
                    }
                } else {
                    result.put(item, pro.getProperty(item));
                }
            }
        } catch (Throwable ex) {
            log.error("不能加载资源:"+resource,ex);
        }
    }
}

⌨️ 快捷键说明

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