Properties配置文件
package file; import java.io.FileOutputStream;
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; /*
Properties(配置文件类 )
1.如果配置文件的信息出现了中文,只能使用字符解决,如果使用字节流,默认是ISO8859-1,会出现乱码。
2.如果Properties中的内容发生了变化,一定要重新存储这个配置文件.
*/
public class Demo11 {
public static void main(String[] args) throws IOException {
// createProperties();
readProperties();
} //读取配置文件信息
public static void readProperties() throws IOException {
//创建Properties
Properties properties = new Properties();
//加载配置文件到properties中,
properties.load(new FileReader("F:\\test.properties"));
//遍历Properties
Set<Entry<Object, Object>> entrys = properties.entrySet();
for(Entry<Object,Object> enrty : entrys) {
System.out.println("键:"+ enrty.getKey() + "值:" + enrty.getValue());
} //修改密码
properties.setProperty("测试", "888");
//重新把修改后的信息properties,在生成一个配置文件
properties.store(new FileWriter("F:\\test.properties"), "he");
} //保存配置文件的信息
public static void createProperties() throws IOException, IOException {
//创建Properties
Properties properties = new Properties();
properties.setProperty("测试", "123");
properties.setProperty("测试2", "234");
properties.setProperty("测试3", "456"); //遍历Properties
// Set<Entry<Object, Object>> entrys = properties.entrySet();
// for(Entry<Object,Object> enrty : entrys) {
// System.out.println("键:"+ enrty.getKey() + "值:" + enrty.getValue());
// } //使用properties产生配置文件
// properties.store(new FileOutputStream("F:\\test.properties"), "ha"); //第一个是输出流对象,第二个是描述信息
properties.store(new FileWriter("F:\\test.properties"), "he"); } }
Properties配置文件的更多相关文章
- 读取.properties配置文件
方法1 public class SSOUtils { protected static String URL_LOGIN = "/uas/service/api/login/info&q ...
- java读取properties配置文件总结
java读取properties配置文件总结 在日常项目开发和学习中,我们不免会经常用到.propeties配置文件,例如数据库c3p0连接池的配置等.而我们经常读取配置文件的方法有以下两种: (1) ...
- properties 配置文件中值换行的问题
在使用properties配置文件的时候我们经常碰到如下两个问题 1:当a=b中的b值内容特别长的时候为了阅读方便我们手动换行,但如果我们直接回车那么后面的数据就会丢失.那如何解决呢? 例如: a=a ...
- properties配置文件的读取和写入
/** * 类名:PropertiesUtil * 功能:提供对properties配置文件的读取和写入 * @author ChengTao */package com.xy.xyd.rest.bi ...
- java读取properties配置文件方法(一)
为了修改项目参数方便,需要使用properties配置文件: 首先是需要三个jar包(不同的jar包,读取配置文件的方式会有所不同,这里使用的是2.6版本的jar包) commons configur ...
- java 顺序 读写 Properties 配置文件
java 顺序 读写 Properties 配置文件 支持中文 不乱码 java 顺序 读写 Properties 配置文件 ,java默认提供的Properties API 继承hashmap ,不 ...
- jdbc基础 (二) 通过properties配置文件连接数据库
csdn博文地址:jdbc基础 (二) 通过properties配置文件连接数据库 上一篇描述了对mysql数据库的简单操作,下面来看一下开发中应该如何灵活应用. 因为jdbc对数据库的驱动加载.连接 ...
- Java 获取*.properties配置文件中的内容 ,常见的两种方法
import java.io.InputStream; import java.util.Enumeration; import java.util.List; import java.util.Pr ...
- Java读取Properties配置文件
1.Properties类与Properties配置文件 Properties类继承自Hashtable类并且实现了Map接口,使用键值对的形式来保存属性集.不过Properties的键和值都是字符串 ...
- 读取Properties配置文件
一,Android中 在Android中读取配置文件,可以使用System.getProperties()方法读取: 1,在res资源目录下,新建一个文件夹 raw,然后在其下创建一个.propert ...
随机推荐
- HDU Train Problem I 1022 栈模拟
题目大意: 给你一个n 代表有n列 火车, 第一个给你的一个字符串 代表即将进入到轨道上火车的编号顺序, 第二个字符串代表的是 火车出来之后到顺序, 分析一下就知道这,这个问题就是栈, 先进后出吗, ...
- winform调用WCF默认实例
一:截图 二:调用代码 using System; using System.Collections.Generic; using System.ComponentModel; using Syste ...
- 利用C++11的function和bind简化类创建线程
问题引出 当在类中需要创建线程时,总是因为线程函数需要定义成静态成员函数,但是又需要访问非静态数据成员这种需求,来做若干重复性的繁琐工作.比如我以前就经常定义一个静态成员函数,然后定一个结构体,结构体 ...
- E - Minimum Cost - POJ 2516(最小费)
题目大意:N个客户,M个供货商,K种商品,现在知道每个客户对每种商品的需求量,也知道每个供货商每种商品的持有量,和供货商把一种商品运送到每个客户的单位花费.现在想知道如果能满足所有客户的最小花费是多少 ...
- win7虚拟机起不来,报错transport vmdb error -44 message the vmware authorization
运行: services.msc 选择:VMware Authorization Service,运行它
- [Unit Testing] Angular Unit Testing, ui-router, httpbackend and spy
// backend test beforeEach(inject(function (_$compile_, _$httpBackend_, _$rootScope_, _$state_, _Ann ...
- C# 将MSMQ消息转换成Json格式 【优化】
C# 将MSMQ消息转换成Json格式 [优化] 转换函数: private string ConvertToJSON(string label, string body) { //TODO: co ...
- atitit。浏览器缓存机制 and 微信浏览器防止缓存的设计 attilax 总结
atitit.浏览器缓存机制 and 微信浏览器防止缓存的设计 attilax 总结 1. 缓存的一些机制 1 1.1. http 304 1 1.2. 浏览器刷新的处理机制 1 1.3. Expir ...
- linux中切换用户方式su和su -的区别
Using su The su command allows users to open a terminal window, and from that terminal start a sub ...
- NYOJ 214 最长上升子序列nlogn
普通的思路是O(n2)的复杂度,这个题的数据量太大,超时,这时候就得用nlogn的复杂度的算法来做,这个算法的主要思想是只保存有效的序列,即最大递增子序列,然后最后得到数组的长度就是最大子序列.比如序 ...