Java读取properties文件

11年前
package com.runqianapp;    import java.util.Properties;       import java.io.InputStream;       import java.io.IOException;     import java.io.FileNotFoundException;    import java.sql.Connection;    import java.sql.DriverManager;</p><p>public class DBUtil {    public void readProperties(){       try {        Properties props = new Properties();        //props.load(getClass().getResourceAsStream("/config/Conn.properties"));         //InputStream is = Object.class.getResourceAsStream("/config/Conn.properties");         InputStream is = Class.forName("com.runqianapp").getClassLoader().getResourceAsStream("config/Conn.properties");        props.load(is);        is.close();        //读取键值        String url = props.getProperty("url");        String name = props.getProperty("name");        String user = props.getProperty("user");        String pwd = props.getProperty("pwd");        //获取数据库连接        Class.forName("驱动类"); //加载驱动        Connection conn = DriverManager.getConnection(url,user,pwd);        System.out.println(conn);     public static void main(String[] args){         DBUtil db = new DBUtil();         db.readProperties();     }    }