当前位置:网站首页>8.Properties属性集合
8.Properties属性集合
2022-08-09 09:23:00 【过来我的小熊】
Properties属性集合
- Properties:用于获取流中的属性集合,时Hashtable的子类,拥有map集合的所有特点
- 位置:java.util.*包下
- 方法:
- void load() 加载一个输入流用于读取数据 (加载)
- void list(PrintStream out) 将打印的数据打印到文件中
- String getProperty(String key) 获取指定键的值
- Object setProperty(String key, String value) 调用Hashtable的方法put
- void store(OutputStream out, String comments) 把setProperty操作后的数据更新到输出流 (保存)
- 特点:
- 存储属性名和属性值
- 属性名和属性值都是字符串类型(键值对)
- 没有泛型
- 和流有关
package com.io.Properties;
import java.io.*;
import java.util.Map;
import java.util.Properties;
/**
* Properties集合的使用
*/
public class Demo1 {
public static void main(String[] args) throws IOException {
// 创建Properties集合对象
Properties properties = new Properties();
// 添加数据
properties.setProperty("username","zhangsan");
properties.setProperty("age","20");
System.out.println(properties.toString());
// 遍历
System.out.println("------keySet方法遍历------");
for (Object key : properties.keySet()) {
System.out.println(key.toString() +"--"+ properties.get(key));
}
System.out.println("------entrySet----------");
for (Map.Entry<Object, Object> entry : properties.entrySet()) {
System.out.println(entry.getKey() + "--" + entry.getValue());
}
System.out.println("------stringPropertyNames---------");
for (String pro : properties.stringPropertyNames()) {
System.out.println(pro + "--" + properties.getProperty(pro));
}
// 和流有关的方法
// list 遍历 方法
// System.out.println("----------list 遍历 方法-----------");
// PrintWriter pw = new PrintWriter("E:\\桌面\\aaa.txt");
// properties.list(pw);
// pw.close();
// store 保存 方法
// System.out.println("-----------store 保存 方法-----------");
// FileOutputStream fos = new FileOutputStream("E:\\桌面\\aaa.properties");
// properties.store(fos,"注释");
// fos.close();
// load 加载 方法
System.out.println("-----------load 加载 方法---------");
Properties properties1 = new Properties();
FileInputStream fis = new FileInputStream("E:\\桌面\\aaa.properties");
properties1.load(fis);
fis.close();
System.out.println(properties1);
}
}
边栏推荐
猜你喜欢
How much do you know about the mobile APP testing process specifications and methods?
接口测试主要测试哪方面?需要哪些技能?要怎么学习?
“摄像头用不了”+win8.1+DELL+外置摄像头+USB免驱的解决办法
手机APP测试流程规范和方法你知道多少?
本体开发日记04-努力理解protege的某个方面
Sweet alert
条件和递归
seata处理分布式事务
MySQL查漏补缺(五)不熟悉的知识点
使用Protege4和CO-ODE工具构建OWL本体的实用指南-1.3版本(7.4 Annotation Properties-注释属性)
随机推荐
运行flutter项目时遇到的问题
功能自动化测试实施的原则以及方法有哪些?
运行flutter项目时遇到的问题修改flutter为国内镜像
全网最全的软件测试基础知识整理(新手入门必学)
中国打造国产“谷歌地球”清晰度吓人
软件测试面试常见问题及答案(发散思维、接口、性能、概念、)
接口设计
字典
MySQL事务隔离
Venture DAO Industry Research Report: Macro and Classic Case Analysis, Model Summary, Future Suggestions
接口测试的基础流程和用例设计方法你知道吗?
Consolidation of Questionnaire Questions and Answers
列表
奥维地图电脑端手机端不能用了,有没有可替代的地图工具
swap交换分区
接口测试的概念、目的、流程、测试方法有哪些?
问卷问题和答案的合并
Read file by byte and character_load configuration file
用户设备IP三者绑定自动上号
字符串