In a project, we can write a class to read the properties.As following,
import java.io.InputStream;
import java.io.IOException;
import java.util.Properties;
public class PropertyReader{
private static Properties property = null;
static{
InputSteam stream = null;
try{
stream=PropertyReader.class.getResourceAsStream("/resource/properties.properties");
property = new Properties();
property.load(stream);
}catch(IOException e){
e.printStackTrace();
}finally{
if(stream != null){
try{
stream.close();
}catch(IOException e){
e.printStackTrace();
}
}
}
}
public static String getResource(String key){
if(property == null){
return null;// init error;
}
return property.getProperty(key);
}
}
posted on 2007-04-05 08:13
wqwqwqwqwq 阅读(477)
评论(0) 编辑 收藏 所属分类:
Simple Java