zoukankan      html  css  js  c++  java
  • 读取配置文件

    //        从配置文件获取连接数据库的信息
    //        通过FileReader 读取配置文件
            FileReader fileReader = new FileReader("conf/server.properties");
            //创建属性对象
            Properties pro = new Properties();
            //通过属性对象的load方法将配置文件的信息加载到内存中生成一个map集合
            pro.load(fileReader);
            //關閉劉
            fileReader.close();
            
            
            String driver = pro.getProperty("driver");
            String url = pro.getProperty("url");
            String user = pro.getProperty("user");
            String password = pro.getProperty("password");
    -----------------------------------------------------------------------------------------------------------------    
        //静态代码块,类加载时候就初始化了
        static{
         //创建属性对象
            Properties properties = new Properties();
            //通过类加载器读取对应的资源
            InputStream is = BaseDao.class.getClassLoader().getResourceAsStream("db.properties");
            try {
           //将is流中的所有数据加载到属性对象中
                properties.load(is);
            } catch (IOException e) {
                e.printStackTrace();
            }
            driver = properties.getProperty("driver");
            url = properties.getProperty("url");
            username = properties.getProperty("username");
            password = properties.getProperty("password");
    
        }
     
  • 相关阅读:
    插入排序
    APPlication,Session,Cookie,ViewState和Cache之间的区别
    sqlserver 2005新特性
    选择排序
    Transact_SQL小手册
    装箱和取消装箱
    select语句的执行步骤:
    using 的三种用法
    创建索引及撤销
    (转译)用FFmpeg和SDL写播放器08软件缩放
  • 原文地址:https://www.cnblogs.com/rzkwz/p/12381124.html
Copyright © 2011-2022 走看看