zoukankan      html  css  js  c++  java
  • 一个软编码资源文件的路径问题

    1 static {
    ResourceBundle res =
    ResourceBundle.getBundle("conn"); // 读取属性文件
    drivers = res.getString(“driver”).trim(); // 读取数据库驱动
    url = res.getString("url").trim(); // 读取数据库连接URL
    username = res.getString("username").trim(); // 读取用户名
    password = res.getString("pwd").trim(); // 读取密码
    }

    2

    static {
    Properties p = new Properties(); // 获取Properties实例
    try {
    p.load(Test2.class.getResourceAsStream("Conn.properties")); // 获取
    Conn.properties文件
    } catch (IOException e) {
    System.out.println("properties file not found" + e.getMessage());
    }
    drivers = p.getProperty("driver"); // 读取数据据驱动
    url = p.getProperty("url"); // 读取数据库连接URL
    username = p.getProperty("username"); // 读取用户名
    password = p.getProperty("pwd"); // 读取密码

    比较1 和2

    1的conn是相对项目根路径!而2是conn.properties是相对当前文档。

  • 相关阅读:
    newgrp
    netstat
    netlink, PF_NETLINK
    netdevice
    mv
    mplayer
    mpg123
    MOVE
    motd
    more
  • 原文地址:https://www.cnblogs.com/zwl24/p/2553665.html
Copyright © 2011-2022 走看看