package com.tsinghua.getDataBaseConn; import java.io.IOException;import java.io.InputStream;import java.util.Properties; public class GetProperty { // 方法一:通过java.util.ResourceBundle读取资源属性文件 public static String getPropertyByName(String path, String n
public class PropertyUtil { public static final Properties PROP = new Properties(); /** * 读取配置文件的内容(key,value) * * @param key * @return key对应的value */ public static String get(String key) { if (PROP.isEmpty()) { try { InputStream in = PropertyUtil.cl
若是Javaweb项目,项目运行于tomcat或其他容器时,可以使用下面方式来获取文件的输入流 1.当属性文件放在src下面时 InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream("test.properties"); Properties p = new Properties(); p.load(is); 2.当属性文件放在某个包下面时,如:com.test.confi
----db.properties-------- dbDriver = oracle.jdbc.driver.OracleDriverurl = jdbc:oracle:thin:@192.168.1.186:1521:jfglorcluserName=jfglpassword=jfgl ------------ JDBConnection ---------------------------- public class JDBConnection { public Connection