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配置文件的更多相关文章

  1. 读取.properties配置文件

    方法1 public  class SSOUtils { protected static String URL_LOGIN = "/uas/service/api/login/info&q ...

  2. java读取properties配置文件总结

    java读取properties配置文件总结 在日常项目开发和学习中,我们不免会经常用到.propeties配置文件,例如数据库c3p0连接池的配置等.而我们经常读取配置文件的方法有以下两种: (1) ...

  3. properties 配置文件中值换行的问题

    在使用properties配置文件的时候我们经常碰到如下两个问题 1:当a=b中的b值内容特别长的时候为了阅读方便我们手动换行,但如果我们直接回车那么后面的数据就会丢失.那如何解决呢? 例如: a=a ...

  4. properties配置文件的读取和写入

    /** * 类名:PropertiesUtil * 功能:提供对properties配置文件的读取和写入 * @author ChengTao */package com.xy.xyd.rest.bi ...

  5. java读取properties配置文件方法(一)

    为了修改项目参数方便,需要使用properties配置文件: 首先是需要三个jar包(不同的jar包,读取配置文件的方式会有所不同,这里使用的是2.6版本的jar包) commons configur ...

  6. java 顺序 读写 Properties 配置文件

    java 顺序 读写 Properties 配置文件 支持中文 不乱码 java 顺序 读写 Properties 配置文件 ,java默认提供的Properties API 继承hashmap ,不 ...

  7. jdbc基础 (二) 通过properties配置文件连接数据库

    csdn博文地址:jdbc基础 (二) 通过properties配置文件连接数据库 上一篇描述了对mysql数据库的简单操作,下面来看一下开发中应该如何灵活应用. 因为jdbc对数据库的驱动加载.连接 ...

  8. Java 获取*.properties配置文件中的内容 ,常见的两种方法

    import java.io.InputStream; import java.util.Enumeration; import java.util.List; import java.util.Pr ...

  9. Java读取Properties配置文件

    1.Properties类与Properties配置文件 Properties类继承自Hashtable类并且实现了Map接口,使用键值对的形式来保存属性集.不过Properties的键和值都是字符串 ...

  10. 读取Properties配置文件

    一,Android中 在Android中读取配置文件,可以使用System.getProperties()方法读取: 1,在res资源目录下,新建一个文件夹 raw,然后在其下创建一个.propert ...

随机推荐

  1. 【转】android 4.3 BLE onCharacteristicWrite没有回调

    原文网址:http://bbs.csdn.net/topics/390882717?page=1 问题1.我在自己程序有开一个Timer定时去readCharacteristic, 每次read可以成 ...

  2. JDK 和JRE的区别

    JRE:Java Runtime Environment/Java运行时环境目标用户:只需要运行Java程序的用户JRE包含了:Deployment,User Interface Toolkits,I ...

  3. B - Networking - poj 1287

    有一些地方需要铺盖电缆,这些地方两点间的路可能不止一条,需要求出来至少需要多少电缆才能让所有的点都连接起来,当然,间接连接也算. /////////////////////////////////// ...

  4. gem安装时出现 undefined method `size' for nil:NilClass (NoMethodError) 的解决办法

    终端输入gem env 得到gem的PATH路径,比如 - GEM PATHS: - /usr/local/ruby/lib/ruby/gems/2.1.0 - /home/vagrant/.gem/ ...

  5. DataGuard体系结构

    一.DataGuard总体结构 总体目标 1.   描述计划和非计划停机的不同因数 2.   DataGuard的主要组件 3.   物理以及逻辑DataGuard的异同 4.   建立DataGua ...

  6. ZOJ1221 && UVA567:Risk(Floyd)

    Risk is a board game in which several opposing players attempt to conquer the world. The gameboard c ...

  7. javascript 如何避免属性访问错误

    var book = {subtitle: "Bible"}; var bookName = book.name.length // 这时候会出错,  因为试图查询这个不存在的对象 ...

  8. [Angular 2] Mapping Streams to Values to Affect State

    While you have multiple streams flowing into your scan operator, you'll need to map each stream to t ...

  9. [Redux] Writing a Todo List Reducer (Toggling a Todo)

    Learn how to implement toggling a todo in a todo list application reducer. let todo = (state = [], a ...

  10. shell 判断文件、目录是否存在

    shell判断文件是否存在   1. shell判断文件,目录是否存在或者具有权限 2. #!/bin/sh 3. 4. myPath="/var/log/httpd/" 5. m ...