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. POJ 1511 SPFA+邻接表 Invitation Cards

    题目大意: 计算从 1 点 到 其他所有点的 往返距离之和, 因为是 有向图, 所以我们需要将图反存 一次, 然后求两次单源最短路, 结果就出来了. #include <iostream> ...

  2. 【转】Android的权限permission

    原文网址:http://blog.csdn.net/nei504293736/article/details/6974599 <uses-permission android:name=&quo ...

  3. SqlServer新建视图

    一.使用SQL Server 2005数据库管理系统创建视图 1. 启动SQL Server 2005. 2. 在“对象资源管理器”窗口中找到Student数据库,打开Student文件夹,在“视图” ...

  4. loadrunner11 安装及破解教程来自百度文库

    http://wenku.baidu.com/link?url=wSdgdZPzSNkftIqPmuz2rLKJ0M7Q3RrfSEdqcoRzfVDMIikj_7OLmLZWgoCiBev3AxvN ...

  5. Java的内存管理与内存泄露

    作为Internet最流行的编程语言之一,Java现正非常流行.我们的网络应用程序就主要采用Java语言开发,大体上分为客户端.服务器和数据库三个层次.在进入测试过程中,我们发现有一个程序模块系统内存 ...

  6. Error on SVN checkout:SSL handshake failed

    最近遇到了一个恼火的问题,在Ubuntu上尝试用svn命令checkout一个https的repository时遇到个错误信息: svn: E175002: Unable to connect to ...

  7. 开源项目AndroidUtil-采用Fragment实现TabHost

    原文出自:方杰|http://fangjie.info/?p=141 转载请注明出处 学习Android也有一段时间了,感觉大部分的Android应用都有很多类似的组件,所以就打算做了这样一个开源项目 ...

  8. H5页开发规范/通用规范

    兼容目标 主流移动设备:iPhone 4+ .三星.魅族.华为.红米.小米1S 以上及主流 Android 千元机型:请特别关注iPhone4/4s.魅族MX4.华为P6等机型 操作系统:iOS 7. ...

  9. 百度地图点聚合MarkerClusterer,性能优化

    参考文献:http://www.cnblogs.com/lightnull/p/6184867.html 百度的点聚合算法 是基于方格和距离的聚合算法,即开始的时候地图上没有任何已知的聚合点,然后遍历 ...

  10. clang和gcc消除警告

    1. clang命令,它的作用是用来消除特定区域的clang的编译警告,-Wgnu则是消除?:警告, 例: #pragma clang diagnostic push #pragma clang di ...