IO流,Properties基本功能和遍历
2024-10-20 21:12:37
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);
}
}
}
最新文章
- 100803C
- 9.2---机器人走方格(CC150)
- Zookeeper 分布式环境搭建
- Autoprefixer处理CSS3属性前缀
- shell &;&; 和 || 的短路使用
- 湖大 11404 manacher
- iOS UITabBarItem 选中图的颜色,设置UIimage的渲染模式
- iOS图片压缩
- (转)Div+CSS布局入门
- USB枚举过程的详细流程
- Java 之 反射
- 【滚动数组】【状压dp】Gym - 100956F - Colored Path
- Xshell 5 配置上传下载命令
- tkinter中树状结构的建立(十四)
- vo类,model类,dto类的作用及划分
- python利用xlrd读取excel文件始终报错原因
- Java常用的经典排序算法:冒泡排序与选择排序
- [翻译] 初看 ASP.NET Core 3.0 即将到来的变化
- Linux和进程内存模型
- Java中 System.arraycopy() 和 Arrays.copyOf()方法