Java进阶-属性类 Properties 类

  1. 目前只需要掌握 Properties 属性类对象的相关方法即可:存 和 取
    • pro.setProperty(key, value)
    • pro.getProperty(key)
  2. Properties 是一个 Map 集合,继承 Hashtable,Properties 的 key 和 value 都是 String 类型
  3. Properties 被称为属性类对象
  4. Properties 是线程安全的
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import java.util.Properties;

public class PropertiesTest01 {

public static void main(String[] args) {
// 创建一个 Properties 对象
Properties pro = new Properties();

// 存
pro.setProperty("name", "wei");
pro.setProperty("password", "123");

// 取
String url = pro.getProperty("name");
String password = pro.getProperty("password");

System.out.println(url + "-->" + password);
}
}