java.util.Properties.getProperty()方法实例

来源:互联网 发布:淘宝用支付宝登录不了 编辑:程序博客网 时间:2024/05/17 19:19

java.util.Properties.getProperty(String key) 方法将搜索此属性列表中指定键的属性值。如果在属性列表中,默认属性列表及其默认值找到了键,然后检查递归。如果未找到该属性的方法返回null。

声明

java.util.Properties.getProperty()方法的声明

public String getProperty(String key)

例子1

package com.yiibai;import java.util.*;public class PropertiesDemo {   public static void main(String[] args) {      Properties prop = new Properties();      // add some properties      prop.put("Height", "200");      prop.put("Width", "150");      prop.put("Scannable", "true");      // get two properties and print them      System.out.println("" + prop.getProperty("Scannable"));      System.out.println("" + prop.getProperty("Width"));   }}

编译和运行

true150

例子2

package com.yiibai;import java.util.*;public class PropertiesDemo {   public static void main(String[] args) {      Properties prop = new Properties();      // 从file中直接导入     FileInputStream fis = null;       fis = new FileInputStream("E://android/JDBCDemo-master/JDBCDemo-master/db.properties");     props.load(fis);
其中db.properties文件的配置为:(键值)DB_DRIVER_CLASS=com.mysql.jdbc.DriverDB_URL=jdbc:mysql://localhost:3306/db_bbsDB_USERNAME=rootDB_PASSWORD=root



0 0