自用读取配置文件工具类ReadConfig

/**
 * 读取配置文件
 * @author 微软中国
 *
 */
public class ReadConfig {

	private static Properties p;
	
	public static String getPath(String key){
		p = new Properties();
		InputStream in = ReadConfig.class.getClassLoader().getResourceAsStream("config.properties");
		String path;
		try {
			p.load(in);
			path = p.getProperty(key);
		} catch (IOException e) {
			e.printStackTrace();
			throw new RuntimeException("配置文件读取失败...");
		}finally{
			if(in != null){
				try {
					in.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
		return path;
	}
}

你可能感兴趣的:(笔记)