解决方案 »
- 如何知道hibernatetemplate中的方法执行成功
- NIO问题!!请各位大侠帮忙解决下性能问题
- 跳转页面也报这种错?
- struts2+spring+hibernate 的问题,新人没有可用分,大家帮忙
- 请问web service如何接收不固定数量的参数?
- 关于Jboss或者websphere如何通过jmx获取状态
- javaBean分页问题
- 做一个Hibernate小例子,出现如下问题~~~:*
- weblogic8.1的数据库存取问题,ejb在oracle可以运行但为什么到了access报错!
- JavaWeb执行定时,一小时一次,当执行某次定时的时堵塞,导致之后的定时无法执行
- tomcat为什么不能访问了?
- 急急急急急急!大婶们求问个问题,关于分层级显示的
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
public class App {
public static void main(String[] args) {
Properties prop = new Properties();
InputStream input = null;
try {
input = new FileInputStream("config.properties");
// load a properties file
prop.load(input);
// get the property value and print it out
System.out.println(prop.getProperty("database"));
System.out.println(prop.getProperty("dbuser"));
System.out.println(prop.getProperty("dbpassword"));
} catch (IOException ex) {
ex.printStackTrace();
} finally {
if (input != null) {
try {
input.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;public class ProperUtil {
private static final String fileName = "/com/ssh/config/properties/system.properties";
private static Properties proper = new Properties();
static{
try {
proper.load(ProperUtil.class.getResourceAsStream(fileName));
} catch (IOException e) {
e.printStackTrace();
}
}
public static String getStringValue(String key,String defultValue){
String value = proper.getProperty(key);
if(HelpUtil.checkEmpty(value)){
return defultValue;
}
return value;
}
public static boolean getBooleanValue(String key,boolean defultValue){
String value = proper.getProperty(key);
if(HelpUtil.checkEmpty(value)){
return defultValue;
}
return Boolean.parseBoolean(value);
}
public static Integer getIntegerValue(String key,Integer defultValue){
String value = proper.getProperty(key);
if(HelpUtil.checkEmpty(value)){
return defultValue;
}
return Integer.parseInt(value);
}
/**
* 读取所有的配置文件信息
* */
public static Map<String, String> getAllProperties(){
Map<String, String> map = new HashMap<String, String>();
Enumeration en = proper.propertyNames();
String key = "";
String value = "";
while(en.hasMoreElements()){
key = (String)en.nextElement();
value = proper.getProperty(key);
map.put(key, value);
}
return map;
}
}这样可以一次性取到整个properties文件的配置
进入http://commons.apache.org/下载