Java读取classpath中配置文件的小例子

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


public class PropLoad {
	
	private static Properties p = new Properties();
	
	static {
		InputStream in = PropLoad.class.getClassLoader().getResourceAsStream("test.properties");
		try {
			p.load(in);
		} catch (IOException e) {
			_INFO_STATIC("load Properties failed");
		}
	}
	
	public static String getKey(String key){
		return p.getProperty(key);
	}
	
	public static void main(String[] agrs){
		System.out.println(PropLoad.getKey("test"));
	}                              

}

 

 

你可能感兴趣的:(Java读取classpath中配置文件的小例子)