Files
javaSE-260914/s-day09/src/com/inmind/properties06/Demo16.java
T

39 lines
1.3 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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);
}
}
}