From f64832ef3305b2b4d5e9d12ee112f934c50a4924 Mon Sep 17 00:00:00 2001 From: xuxin <840198532@qq.com> Date: Sat, 21 Mar 2026 15:50:52 +0800 Subject: [PATCH] =?UTF-8?q?=E8=BF=9B=E9=98=B6day09-Properties=20=E7=9A=84?= =?UTF-8?q?=E7=89=B9=E7=82=B9=E4=B8=8E=E5=9F=BA=E6=9C=AC=E4=BD=BF=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../inmind/properties06/PropertiesDemo18.java | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 javaSE-day09/src/com/inmind/properties06/PropertiesDemo18.java diff --git a/javaSE-day09/src/com/inmind/properties06/PropertiesDemo18.java b/javaSE-day09/src/com/inmind/properties06/PropertiesDemo18.java new file mode 100644 index 0000000..4ac11c3 --- /dev/null +++ b/javaSE-day09/src/com/inmind/properties06/PropertiesDemo18.java @@ -0,0 +1,38 @@ +package com.inmind.properties06; + +import java.util.Properties; +import java.util.Set; + +/* + Properties 的特点与基本使用(重点) + + 构造方法 + public Properties() :创建一个空的属性列表。 + + 常用的存储方法 + public Object setProperty(String key, String value) : 保存一对属性。 + public String getProperty(String key) :使用此属性列表中指定的键搜索属性值。 + public Set stringPropertyNames() :所有键的名称的集合。 + + 注意: + 1.Properties类似一个HashMap + 2.它的真正作用是,能够将指定的配置文件的信息读取到properties对象中 + */ +public class PropertiesDemo18 { + public static void main(String[] args) { + //创建属性集对象 + Properties properties = new Properties(); + //保存属性键值对 + /*properties.put("username", "admin"); + properties.put("password", "123");*/ + properties.setProperty("username", "admin"); + properties.setProperty("password", "123"); + + Set keys = properties.stringPropertyNames(); + System.out.println(keys); + + System.out.println(properties); + + + } +}