配置文件读取工具类

时间:2022-05-30 11:23:18

DocumentConfigUtil.java

package com.lmb.common.util;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public class DocumentConfigUtil {

private static Properties prop = null;
private static Properties address = null;
private static InputStream in = null;
private static InputStream inAddr = null;

static{
in = DocumentConfigUtil.class.getClassLoader().getResourceAsStream("documentconfig.properties");
inAddr = DocumentConfigUtil.class.getClassLoader().getResourceAsStream("addressconfig.properties");
prop = new Properties();
address = new Properties();
try {
prop.load(in);
address.load(inAddr);
} catch (IOException e) {
throw new RuntimeException(e);
}
}

//得到包括documentconfig文件输入流的对象
public static Properties getDocumentConfig(){
return prop;
}

//得到addressconfig文件输入流的对象
public static Properties getPath(){
return address;
}

public static void main(String[] args) {
System.out.println(getDocumentConfig());
System.out.println(" ");
System.out.println(getPath());
}
}

配置文件读取工具类