zoukankan      html  css  js  c++  java
  • 获取properties中对应的值

    import java.io.IOException;
    import java.util.Properties;
    import java.util.ResourceBundle;
    public class PropertiesUtil {
      public static final String FILE_PATH = "jdbc.properties";

      /**
      * .properties 文件返回 Properties对象
      * @return
      */
      public static Properties getProperties(){
        Properties properties = new Properties();
        try{
          properties.load(PropertiesUtil.class.getClassLoader().getResourceAsStream(FILE_PATH));
        }catch (IOException e){
          throw new RuntimeException("File Read Failed...", e);
        }
        return properties;
      }

      /**
      * 测试 获取jdbc.properties 内容
      */
      public static void main(String[] args) {
        //方法一:调用上述方法获取
        String sqlserverclassname1 = getProperties().getProperty("sqlserverclassname");
        //方法二:如下
        String sqlserverclassname2 = ResourceBundle.getBundle("jdbc").getString("sqlserverclassname");
        System.out.println("sqlserverclassname1=="+sqlserverclassname1);
        System.out.println("sqlserverclassname2=="+sqlserverclassname2);
      }
    }

    打印结果:

  • 相关阅读:
    Shell,Bash,等脚本学习(有区别)
    nfs 服务器
    awk的简单使用
    GPRS研究(3):NO CARRIER错误的含义解释
    信号量
    Linux 的多线程编程的高效开发经验
    getaddrinfo()函数详解
    iOS 知识点
    UITableView拉伸效果
    在Xcode中使用Git进行源码版本控制
  • 原文地址:https://www.cnblogs.com/cai170221/p/13161360.html
Copyright © 2011-2022 走看看