Java讀取屬性文件的屬性

直接使用Java的資源綁定,可以直接獲取到屬性

public class JavaReadProDemo {

    public static void main(String[] args) {
        ResourceBundle dbPro = ResourceBundle.getBundle("db");
        String dricerclass = dbPro.getString("dricerclass");
        String url = dbPro.getString("url");
        String username = dbPro.getString("username");
        String password = dbPro.getString("password");
        System.out.println(dricerclass);
        System.out.println(url);
        System.out.println(username);
        System.out.println(password);
    }
}

db.properties

dricerclass=oracle.jdbc.driver.OracleDriver
url=jdbc:oracle:thin:@192.168.0.1:1521:orcl
username=scott
password=tiger

輸出結果

oracle.jdbc.driver.OracleDriver
jdbc:oracle:thin:@192.168.0.1:1521:orcl
scott
tiger
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章