import java.io.InputStream;
import java.util.Properties;
/**
* @author 李晨
* @version 創建時間:Jul 17, 2009 3:11:40 PM
*/
public class SuperPath {
/**
* 從配置文件取值
* @param fileName 配置文件名
* @return 從指定key得到的value
*/
public String getPara(String fileName) {
Properties prop = new Properties();
try {
// ClassLoader cl = this.getClass().getClassLoader();
// InputStream is = cl.getResourceAsStream(fileName);
InputStream is = this.getClass().getResourceAsStream(fileName);
prop.load(is);
if (is != null)
is.close();
} catch (Exception e) {
System.out.println(e + "file " + fileName + " not found");
}
/**
* 指定哪個key
*/
return prop.getProperty( "keykey");
}
public static void main(String[] args) {
SuperPath sp= new SuperPath();
System.out.println(sp.getPara( "test.properties"));
}
}
本文出自 “wIsper 把技術做成藝術” 博客,請務必保留此出處http://lichen.blog.51cto.com/697816/189964
轉載於:https://my.oschina.net/lichen/blog/264911