Properties 继承于 Hashtable,用于管理配置信息的类。

由于 Properties 继承自 Hashtable 类,因此具有 Hashtable 的所有功能,同时还提供了一些特殊的方法来读取和写入属性文件。

Properties 类常用于存储程序的配置信息,例如数据库连接信息、日志输出配置、应用程序设置等。使用Properties类,可以将这些信息存储在一个文本文件中,并在程序中读取这些信息。

读取文件

public static void main(String[] args) throws IOException {
    Properties properties = new Properties();
    properties.load(new FileInputStream("test.properties"));
    System.out.println(properties);
}

获取系统配置信息

public static void main(String[] args) throws IOException {
    System.getProperties().store(System.out, "系统信息:");
}