Properties集合中的方法store

public class Demo01Properties {
public static void main(String[] args) throws IOException {
show02();
} private static void show02() throws IOException {
// 1.一般使用"空字符串"创建Properties集合对象,添加数据
Properties prop = new Properties();
prop.setProperty("赵丽颖", "167");
prop.setProperty("迪丽热巴", "169");
prop.setProperty("古力娜扎", "170"); //2.创建字节输出流/字符输出流对象,构造方法中绑定要输出的目的地
/* FileWriter fw = new FileWriter("day09_IOAndProperties\\prop.txt"); //3.使用Properties集合中的方法store,把集合中的临时数据,持久化写入到硬盘中存储
prop.store(fw,"save data"); //4.释放资源
fw.close();*/ //字节流,中文乱码
prop.store(new FileOutputStream("day09_IOAndProperties\\\\prop.txt"), "");
}
}

Properties集合中的方法load

可以使用Properties集合中的方法load,把硬盘中保存的文件(键值对),读取到集合中使用

void load(InputStream inStream)

void load(Reader reader)

  参数:

    InputStream inStream:字节输入流,不能读取含有中文的键值对

    Reader reader:字符输入流,能读取含有中文的键值对
  使用步骤:

    1.创建Properties集合对象

    2.使用Properties集合对象中的方法load读取保存键值对的文件

    3.遍历Properties集合

  注意:

    1.存储键值对的文件中,键与值默认的连接符号可以使用=,空格(其他符号)

    2.存储键值对的文件中,可以使用#进行注释,被注释的键值对不会再被读取

    3.存储键值对的文件中,键与值默认都是字符串,不用再加引号

public class Demo01Properties {
public static void main(String[] args) throws IOException {
show03();
} /*
可以使用Properties集合中的方法load,把硬盘中保存的文件(键值对),读取到集合中使用
void load(InputStream inStream)
void load(Reader reader)
参数:
InputStream inStream:字节输入流,不能读取含有中文的键值对
Reader reader:字符输入流,能读取含有中文的键值对
使用步骤:
1.创建Properties集合对象
2.使用Properties集合对象中的方法load读取保存键值对的文件
3.遍历Properties集合
注意:
1.存储键值对的文件中,键与值默认的连接符号可以使用=,空格(其他符号)
2.存储键值对的文件中,可以使用#进行注释,被注释的键值对不会再被读取
3.存储键值对的文件中,键与值默认都是字符串,不用再加引号
*/
private static void show03() throws IOException {
//1.创建Properties集合对象
Properties prop = new Properties();
//2.使用Properties集合对象中的方法load读取保存键值对的文件
prop.load(new FileReader("prop.txt"));
//prop.load(new FileInputStream("prop.txt"));
//3.遍历Properties集合
Set<String> set = prop.stringPropertyNames();
for (String key : set) {
String value = prop.getProperty(key);
System.out.println(key+"="+value);
}
}
}

最新文章

  1. layabox 引擎
  2. get与post
  3. IIS Express 一个网站配置多个 域名
  4. 浅谈B+树索引的分裂优化(转)
  5. bzoj2801
  6. 在Code First中使用Migrations对实体类和数据库做出变更
  7. [Javascript] Intro to the Web Audio API
  8. Windows下文件列举,搜索
  9. 解析Properties文件
  10. javascript操作select元素一例
  11. .Net页面缓存OutPutCache详解
  12. LeetCode题解之Sort List
  13. Requests: 让 HTTP 服务人类
  14. Android开发训练之第五章第三节——Transferring Data Without Draining the Battery
  15. 团队作业4Alpha冲刺(真.三英战吕布团队)
  16. 把对象转换成JSON形式的html代码
  17. PhantomJS、Selenium、Chrome驱动的mac版安装和配置
  18. span文字里面自动换行时怎么办
  19. 【LeetCode】shell
  20. JDK的图文安装教程

热门文章

  1. victoriaMetrics中的一些Sao操作
  2. B+树能存多少数据?
  3. 关于IPC和PTH用户权限问题,psexec拒绝访问(Access Denied)的原因
  4. srpingboot拦截器
  5. Java多线程编程实战02:多线程编程模型
  6. 论文解读(GMIM)《Deep Graph Clustering via Mutual Information Maximization and Mixture Model》
  7. 【Java8新特性】Optional 类
  8. Fail2ban 使用Fail2ban监禁SSH服务的恶意IP
  9. TypeError: this.getOptions is not a function
  10. hexo + typora 图片插入解决办法