`
wjjbfq
  • 浏览: 80566 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

读取properties文件的方法

阅读更多
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.Properties;

public class DBConfigReader {
 private static Properties  dbconfigProperties= new Properties();
 static{
  InputStream is = null;
  try {
   //is = new FileInputStream("src/db.properties");
   ClassLoader classLoader = DBConfigReader.class.getClassLoader();
   is = classLoader.getResourceAsStream("db.properties");
   dbconfigProperties.load(is);
   
   is.close();
  } catch (Exception e) {
   // TODO Auto-generated catch block
   e.printStackTrace();
  }
 }
 
 public static String getDriver(){
  return dbconfigProperties.getProperty("driverName");
 }
 
 public static String getURL(){
  return dbconfigProperties.getProperty("url");
 }
 
 public static String getUsername(){
  return dbconfigProperties.getProperty("username");
 }
 public static String getPassword(){
  return dbconfigProperties.getProperty("password");
 }
 public static void main(String[]argvs){
  System.out.println(getDriver());
 }
}

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics