定义:Properties 继承于 Hashtable.表示一个持久的属性集.属性列表中每个键及其对应值都是一个字符串。
- 注意这里的持久,也就是说他可以以文件的形式存在
package com.fs.myProperties;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Enumeration;
import java.util.Properties;
public class PropertiesTest {
public static void main(String[] args) throws IOException {
Properties properties = new Properties();
// 读
BufferedInputStream in = new BufferedInputStream(new FileInputStream(\"test.properties\"));
properties.load(in);
Enumeration<?> keys = properties.propertyNames();
while (keys.hasMoreElements()) {
key = ( ) keys.nextElement();
System.out.println(key + \":\" + properties.get(key));
}
in.close();
// 写
BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(\"test.properties\"));
properties.setProperty(\"sex\", \"man\");
properties.store(out, \"sex\");
out.close();
}
}
- 项目下的test.properties文件
#sex
#Tue Oct 16 17:19:39 CST 2018
age=18
name=lzl
sex=man
继续阅读与本文标签相同的文章
上一篇 :
jQuery中的DOM操作
-
Docker 做资源限制
2026-05-18栏目: 教程
-
JavaScript 基础类型,数据类型
2026-05-18栏目: 教程
-
[MySQL] docker下安装使用mysql配置主从复制
2026-05-18栏目: 教程
-
微信小程序实现点击改变icon的颜色样式
2026-05-18栏目: 教程
-
微信小程序的接口请求
2026-05-18栏目: 教程
