s-day09--Properties 的特点与基本使用(重点)
This commit is contained in:
@@ -0,0 +1,38 @@
|
|||||||
|
package com.inmind.properties06;
|
||||||
|
|
||||||
|
import java.util.Properties;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
|
/*
|
||||||
|
19.Properties 的特点与基本使用(重点)
|
||||||
|
|
||||||
|
构造方法
|
||||||
|
public Properties() :创建一个空的属性列表。
|
||||||
|
|
||||||
|
常用的存储方法
|
||||||
|
public Object setProperty(String key, String value) : 保存一对属性。
|
||||||
|
public String getProperty(String key) :使用此属性列表中指定的键搜索属性值。
|
||||||
|
public Set<String> stringPropertyNames() :所有键的名称的集合。
|
||||||
|
|
||||||
|
注意:
|
||||||
|
1.Properties类似一个HashMap
|
||||||
|
2.它真正的作用,能够将指定的配置文件的信息读取到Properties的对象
|
||||||
|
*/
|
||||||
|
public class Demo16 {
|
||||||
|
public static void main(String[] args) {
|
||||||
|
Properties properties = new Properties();
|
||||||
|
//存放键值对
|
||||||
|
properties.setProperty("username","lisi");
|
||||||
|
properties.setProperty("password","123456");
|
||||||
|
properties.setProperty("email","111@qq.com");
|
||||||
|
//格局属性键找值
|
||||||
|
Object value = properties.get("username");
|
||||||
|
System.out.println(value);
|
||||||
|
System.out.println(properties.get("password"));
|
||||||
|
|
||||||
|
Set<String> keys = properties.stringPropertyNames();
|
||||||
|
for (String key : keys) {
|
||||||
|
System.out.println(key);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user