import java.util.Enumeration;
import java.util.Iterator;
import java.util.Properties;
import java.util.Set; public class PropertiesDemo {
public static void main(String[] args) {
Properties properties = new Properties();
properties.put("zhangsan", "23");
properties.put("lisi", "25");
properties.put("wangwu", "21");
properties.put("zhaoliu", "27");
Set<String> names = properties.stringPropertyNames();
//使用高级for遍历
for(String name : names) {
String value = properties.getProperty(name);
System.out.println(name + " = " + value);
}
//使用迭代器遍历
Iterator<String> iterable = names.iterator();
while(iterable.hasNext()){
String key = iterable.next();
String value = properties.getProperty(key);
System.out.println(key +" = " + value);
}
//使用枚举遍历
Enumeration<String> enumeration = (Enumeration<String>)properties.propertyNames();
while(enumeration.hasMoreElements()) {
String key = enumeration.nextElement();
String value = properties.getProperty(key);
System.out.println(key + " = " + value);
}
}
}

IO流,Properties基本功能和遍历的更多相关文章

  1. Java IO流-Properties

    2017-11-05 21:37:50 Properties Properties:Properties 类表示了一个持久的属性集.Properties 可保存在流中或从流中加载.属性列表中每个键及其 ...

  2. IO流——Properties类、序列化流、反序列化流、打印流、commons-IO

    一. Properties类 1. Properties类介绍 Properties 类表示了一个持久的属性集.Properties 可保存在流中或从流中加载.属性列表中每个键及其对应值都是一个字符串 ...

  3. JavaEE基础(二十二)/IO流

    1.IO流(序列流) 1.什么是序列流 序列流可以把多个字节输入流整合成一个, 从序列流中读取数据时, 将从被整合的第一个流开始读, 读完一个之后继续读第二个, 以此类推. 2.使用方式 整合两个: ...

  4. day22<IO流+>

    IO流(序列流) IO流(序列流整合多个) IO流(内存输出流) IO流(内存输出流之黑马面试题) IO流(对象操作流ObjecOutputStream) IO流(对象操作流ObjectInputSt ...

  5. 阶段1 语言基础+高级_1-3-Java语言高级_06-File类与IO流_06 Properties集合_1_使用Properties集合存储数据,遍历取出集合中的数据

    map下面的实现类叫做Hashtable Properties是唯一和IO流相结合的 讲解 代码

  6. Java API —— IO流(数据操作流 & 内存操作流 & 打印流 & 标准输入输出流 & 随机访问流 & 合并流 & 序列化流 & Properties & NIO)

    1.操作基本数据类型的流     1) 操作基本数据类型 · DataInputStream:数据输入流允许应用程序以与机器无关方式从底层输入流中读取基本 Java 数据类型.应用程序可以使用数据输出 ...

  7. IO流--与properties集合配合使用

    IO流--与properties集合配合使用: 注:生产上主要用于常量文件的配置,读取常量文件: 1:properties集合的放值与取值: /* * properties集合继承自hashTable ...

  8. IO(Properties、序列化流、打印流、CommonsIO)

    第1章 Properties类 1.1 Properties类介绍 Properties 类表示了一个持久的属性集.Properties 可保存在流中或从流中加载.属性列表中每个键及其对应值都是一个字 ...

  9. IO流的Properties集合,序列化流与反序列化流,打印流及commons-IO

    内容介绍 Properties集合 序列化流与反序列化流 打印流 commons-IO Properties类 Properties类介绍 Properties 类表示了一个持久的属性集.Proper ...

随机推荐

  1. 09_Redis持久化——AOF方式

    [AOF简述] AOF(Append-only) Redis每次接受到一条改变数据的命令时,它会把该命令写到一个AOF文件中(只记录写操作,不记录读操作),当Redis启动时,它通过执行AOF文件中的 ...

  2. java 从网上下载文件的几种方式

    package com.github.pandafang.tool; import java.io.BufferedOutputStream; import java.io.File; import ...

  3. 什么是shell? bash和shell有什么关系?

    什么是Shell?      shell是你(用户)和Linux(或者更准确的说,是你和Linux内核)之间的接口程序.你在提示符下输入的每个命令都由shell先解释然后传给Linux内核.      ...

  4. 一张图看懂CSS cascade, specific, importance, inheritance

    http://www.w3.org/TR/CSS21/cascade.html#inheritance http://www.w3.org/TR/CSS21/cascade.html#cascade ...

  5. 【Leetcode】【Medium】Populating Next Right Pointers in Each Node

    Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *nex ...

  6. Android Studio添加取消代码注释快捷键

    经常需要注释,取消注释代码 Ctrl + /       对每段代码前面添加或者取消 // Ctrl + Shift + /   对代码添加 或取消 /* */ Ctrl + B     查找定义 C ...

  7. linux:相关命令以及笔记

    首先,在linux 或者 unix里没有任何的反馈就叫成功,例如: (1)命令执行成功的样子:返回了登录用户信息 (2)命令执行失败的样子:没有返回任何东西 1.按键出现状况 解决:可以使用ctrl+ ...

  8. February 14 2017 Week 7 Tuesday

    Love lives in cottages as well as in courts. 爱情无贵贱,贫富皆有之. Many people, especially boys, complain tha ...

  9. easyui学习笔记11—tab标签页和鼠标动作

    这篇我们看看标签页是怎么实现的,默认情况下要靠点击切换标签,也可以用鼠标切换标签选项,就是鼠标放在标签上切换. 首先看看引用的资源文件 1.资源文件 <head> <meta cha ...

  10. Ubuntu16.04更换NVIDIA驱动导致无法进入图形界面的解决方案

    一.进入recovery模式 由于无法进入图形界面,所以需要在开机时进入恢复模式.我的机器上时在开机时通过引导选项中的recovery mode选项进入,进入之后可以看到许多选项卡,选择root,回车 ...