java Properties 配置信息类
Properties(配置信息类):主要用于生产配置文件和读取配置文件信息。
----> 是一个集合类 继承HashTable 存值是以键-值的方式。
package com.beiwo.io; import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Map.Entry;
import java.util.Properties;
import java.util.Set; public class demo5 { public static void main(String[] args) throws IOException {
// 调用方法
creatPeoperties();
readPeoperties();
} }
写入配置信息方法:
public static void creatPeoperties() throws IOException {
// 创建properties对象
Properties properties = new Properties();
// 配置信息 键 和值都是字符串
properties.setProperty("张三", "123");
properties.setProperty("李四", "234");
properties.setProperty("王五", "345");
properties.setProperty("赵六", "456");
properties.setProperty("宋七", "567");
// 将配置信息写入磁盘中
properties.store(new FileWriter("C:\\Users\\cdlx2016\\Desktop\\2\\User.properties"), "这是用户配置信息");
}
读取配置的信息
public static void readPeoperties() throws IOException, IOException {
// 创建peoperties对象
Properties properties = new Properties();
properties.load(new FileReader("C:\\Users\\cdlx2016\\Desktop\\2\\User.properties"));
// 遍历配置信息
Set<Entry<Object, Object>> entrys = properties.entrySet();
for (Entry<Object, Object> entry : entrys) {
System.out.println("key: " + entry.getKey() + " -- value: " + entry.getValue());
}
}
java Properties 配置信息类的更多相关文章
- java 配置信息类 Properties 的简单使用
Properties :(配置信息类) 是一个表示持久性的集合 ,继承 Hashtable ,存值是以键-值得方式 主要用于生产配置文件和读取配置文件信息. 简单的实例: import java.i ...
- Html.java 存储页面信息类
Html.java 存储页面信息类 package com.iteye.injavawetrust.miner; /** * 存储页面信息类 * @author InJavaWeTrust * */ ...
- spring boot mybatis XML文件读取properties配置信息
配置文件application.properties中相关配置信息可以在部署以后修改,引用配置信息可以在代码和mybatis的映射文件中 1.JAVA代码 可以通过变量去读取 application. ...
- JAVA 获取jdbc.properties配置信息
Properties myProperty = new Properties();String jdbcPath = PathKit.getWebRootPath()+File.separator+& ...
- 读取.properties配置信息
package com.ctcti.webcallcenter.utils; import java.io.FileInputStream;import java.io.FileNotFoundExc ...
- Java properties配置文件工具类
/* * Copyright (c) 2017. Panteng.Co.Ltd All rights reserved */ import org.apache.log4j.Logger; impor ...
- java将配置信息写在数据库(利用反射)
Demo出处: 1. package com.fpx.pcs.prealert.process.xml.service.impl; public class CainiaoPushMessageSer ...
- Properties --- C++读配置信息的类(一)
http://blog.csdn.net/billow_zhang/article/details/4304980 在开发实践中,积累了一些通用的C++ 类库,在此写出来给大家分享.也希望能给出更好的 ...
- Properties --- C++读配置信息的类
http://blog.csdn.net/billow_zhang/article/details/4304980 在开发实践中,积累了一些通用的C++ 类库,在此写出来给大家分享.也希望能给出更好的 ...
随机推荐
- Android之自定义属性
有些时候会觉得Android中提供的控件不能满足项目的要求,所以就会常常去自定义控件.自定义控件就不免会自定义属性.自定义属性大致需要三个步骤:在XML文件中定义自定义属性的名称和数据类型.在布局中调 ...
- ZOJ 3699 Dakar Rally
Dakar Rally Time Limit: 2 Seconds Memory Limit: 65536 KB Description The Dakar Rally is an annu ...
- MyEclispe发布web项目-遁地龙卷风
(-1)写在前面 我用的是MyEclipse8.5. 还记得以前帮助一个女同学解决问题的时候,特意情调了要先启动服务在发布项目,其实单独的时候都是知道的,总和起来后就容易片面的给出结论.因为不会发生问 ...
- JVM相关参数的采集
1.以-jar方式启动jar包: java -Dcom.sun.management.jmxremote=true -Dcom.sun.management.jmxremote.port=40100 ...
- Java Native Interface 二 JNI中对Java基本类型和引用类型的处理
本文是<The Java Native Interface Programmer's Guide and Specification>读书笔记 Java编程里会使用到两种类型:基本类型(如 ...
- request response
request 和 response 这两个对象是出现在service方法中.service方法是用来接收请求处理请求,完成响应的. 接受请求指的就是request对象 完成响应指的就 ...
- Python 开发轻量级爬虫06
Python 开发轻量级爬虫 (imooc总结06--网页解析器) 介绍网页解析器 将互联网的网页获取到本地以后,我们需要对它们进行解析才能够提取出我们需要的内容. 也就是说网页解析器是从网页中提取有 ...
- Assertion failure in -[UITableView _configureCellForDisplay:forIndexPath:]
今天遇到了Assertion failure in -[UITableView _configureCellForDisplay:forIndexPath:]这个错误,一直也没有百度,不料想却弄了一个 ...
- Java控件(日常笔记)
Java的一些控件 text:文本区域 readonly属性:是否只读.password:密码区域,输入的文本以'*'展示checkbox:复选框 checked属性:是否选中:radio:单选框: ...
- mvc+webapi 项目架构
首先项目是mvc5+webapi2.0+orm-dapper+ef codefirst+redis+quartz.net+actionmq. 1.项目框架层次结构: 这个mvc项目根据不同的业务和功能 ...