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

    第一种

     1 try{
     2                 //读取配置文件
     3                 Properties prop = new Properties();            
     4                 InputStream is = DBUtil.class.getClassLoader().getResourceAsStream("config.properties");
     5                 prop.load(is);
     6                 is.close();
     7         
     8                 //获取驱动
     9                 String driver = prop.getProperty("jdbc.className");
    10                 
    11                 System.out.println(driver);
    12                 //获取地址
    13                 url = prop.getProperty("jdbc.url");
    14                 
    15                 //获取用户名
    16                 user = prop.getProperty("jdbc.username");
    17             
    18                 //获取密码
    19                 pwd = prop.getProperty("jdbc.password");
    20                             
    21                 //注册驱动
    22                 Class.forName(driver);
    23                 
    24             }catch(Exception e){
    25                 e.printStackTrace();
    26             }

    第二种

                Properties prop = new Properties();
                try {
                    String path = "WEB-INF/classes";
                    path = request.getSession().getServletContext().getRealPath(path);
    
                    InputStream is = new FileInputStream(path+"/arcgis.properties");
                    prop.load(is);
                    is.close();
                    String mapserver = prop.getProperty("MAPSERVER");
                    model.addAttribute("mapserver", mapserver);
                    return "view/gp/bian_all";
                } catch (Exception e) {
                    e.printStackTrace();
                    return null;
                }
  • 相关阅读:
    继续无题
    关于自杀的一些观点
    详解js运算符
    数据库批量 之 Oracle
    数据库批量 之 DB2
    linux压缩(解压缩)命令详解
    Cron
    解压命令
    常见web错误码
    cmd命令大全
  • 原文地址:https://www.cnblogs.com/xiaotian-222/p/6707878.html
Copyright © 2011-2022 走看看