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 ...
随机推荐
- fmt命令
简单的格式化文本 fmt [option] [file-list] fmt通过将所有非空白行的长度设置为几乎相同,来进行简单的文本格式化 参数 fmt从file-list中读取文件,并将其内容的格式化 ...
- Java程序员容易犯的10个错误
1. Array 转 ArrayList 一般开发者喜欢用: List<String> list = Arrays.asList(arr); Arrays.asList() 会返回一个Ar ...
- HDU3631:Shortest Path(Floyd)
Problem Description When YY was a boy and LMY was a girl, they trained for NOI (National Olympiad in ...
- django种表单post出现CSRF verification failed( CSRF验证失败 ) 的两种解决方式
现象 表单界面例如以下: watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvc29sbG9yNTI1/font/5a6L5L2T/fontsize/400/fi ...
- oracle REGEXP_SUBSTR实现字符串转列
如将字符串'张三,李四,王五,赵六,'转换成 1. 张三 2.李四 3.王五 4.赵六 REGEXP_SUBSTR 查询语句: WITH TEST AS (SELECT '张三,李四,王五,赵六, ...
- logcat使用
做android有些日子了,只是对主要的logcat的具体使用方法还是非常模糊,今天有空,学习一下. logcat能够在adb中使用,也能够直接在命令行下使用. logcat [options] [f ...
- PC端QQ协议解析之0825
QQ协议0825代号解析,包括客户端发送包和服务器发送包. 主要借鉴的此篇文章,我自己也是重复造轮子. 基本信息 操作系统:windows7 QQ-Version:3643 客户端到服务器: 02:数 ...
- 选课 树形dp+路径输出
#include<iostream> #include<cstdio> #include<cstring> #define maxn 2010 using name ...
- codevs 4827 妹子
/* 赤裸裸的数学题 各种整体+插空 所以嘛 学好数学还是很重要的 ans=(n-1)!*(m-1)!*(2+(n-2)(n-1)) */ #include<iostream> #incl ...
- Try,Catch,Finally三块中如果有Return是怎么个运行顺序
今天看一个Java SSH的面试题,题目大概意思是:try.catch中存在return语句,还会执行finally块吗?如果执行,是return先执行还是finally先执行?如果有多个return ...