笔记

public class Config {

     private static Properties props = new Properties();
static File configFile = null;
static {
InputStreamReader reader = null;
try {
File dir = new File(System.getProperty("user.dir"));
configFile = new File(dir, "config.properties.dev");
if (!configFile.exists()) {
// String path = Thread.currentThread().getClass().getClassLoader().getResource("config.properties").getPath();
// configFile = new File(path);
configFile = new File(dir, "config.properties");
}
reader = new InputStreamReader(new FileInputStream(configFile), "UTF-8");
props.load(reader);
} catch (FileNotFoundException e) {
} catch (Exception e) {
} finally {
if (reader != null) {
try {
reader.close();
} catch (IOException e) {
}
}
}
} public static String getDsl(){
System.out.println("dsl" + props.getProperty("dsl"));
return props.getProperty("dsl");
} public static String getDate(){
System.out.println("date" + props.getProperty("date"));
return props.getProperty("date");
} public static void updateProperties(String keyname,String keyvalue) {
try {
props.load(new FileInputStream(configFile));
// 调用 Hashtable 的方法 put,使用 getProperty 方法提供并行性。
// 强制要求为属性的键和值使用字符串。返回值是 Hashtable 调用 put 的结果。
props.setProperty(keyname, keyvalue);
OutputStream fos = new FileOutputStream(configFile);
// 以适合使用 load 方法加载到 Properties 表中的格式,
// 将此 Properties 表中的属性列表(键和元素对)写入输出流
props.store(fos, "Update '" + keyname + "' value");
} catch (IOException e) {
System.err.println("属性文件更新错误");
}
} }

java 读取配置文件 与更新的更多相关文章

  1. java读取配置文件的几种方法

    java读取配置文件的几种方法 原文地址:http://hbcui1984.iteye.com/blog/56496         在现实工作中,我们常常需要保存一些系统配置信息,大家一般都会选择配 ...

  2. Java读取配置文件的方式

    Java读取配置文件的方式-笔记 1       取当前启动文件夹下的配置文件   一般来讲启动java程序的时候.在启动的文件夹下会有配置文件 classLoader.getResource(&qu ...

  3. java读取配置文件(转)

    转载:http://blog.csdn.net/gaogaoshan/article/details/8605887 java 4种方式读取配置文件 + 修改配置文件     方式一:采用Servle ...

  4. java读取配置文件

    java 读取文件可以用字节流和字符流. 由于一个汉字占两个字节,所以如果配置文件中有汉字,用字节流读取,会出现乱码. 用字符流则不会出现乱码. 配置文件 b.properties 文件如下: fam ...

  5. Java 读取配置文件数据

    Properties类 Properties类,是一个工具类,包含在java.util包中. 功能:可以保存持久的属性,通常用来读取配置文件或者属性文件,将文件中的数据读入properties对象中, ...

  6. java读取配置文件方法以及工具类

    第一种方式 : java工具类读取配置文件工具类 只是案例代码  抓取异常以后的代码自己处理 import java.io.FileNotFoundException; import java.io. ...

  7. java读取配置文件内容

    利用com.typesafe.config包实现 <dependency> <groupId>com.typesafe</groupId> <artifact ...

  8. spring boot使用java读取配置文件,DateSource测试,BomCP测试,AnnotationConfigApplicationContext的DataSource注入

    一.配置注解读取配置文件         (1)@PropertySource可以指定读取的配置文件,通过@Value注解获取值   实例:           @PropertySource(val ...

  9. 使用Java读取配置文件

    实现起来,相对比较简单,留个备案吧,废话也不多说,请看代码: package com.jd.***.config; import org.junit.*; import java.io.IOExcep ...

随机推荐

  1. 【luogu P4231 三步必杀】 题解

    题目链接:https://www.luogu.org/problemnew/show/P4231 诶 我很迷啊..这跟树状数组有什么关系啊...拿二阶差分数组过了..? #include <cs ...

  2. 【luogu P1972 [SDOI2009]HH的项链】 题解

    题目链接:https://www.luogu.org/problemnew/show/P1972 真是不懂为什么要卡莫队! #include <cmath> #include <cs ...

  3. 运行Python

    安装好python环境,在Windows系统下运行cmd命令行,是windows提供的命令行模式. 在命令行下,可以执行python进入Python交互式环境,也可以执行python hello.py ...

  4. mysql的子查询in()操作及按指定顺序显示

    代码示例: in(逗号分隔开的值列表) 释:是否存在于值列表中 --------------------- 示例: select * from test where id in(3,1,5) orde ...

  5. ABAP术语-Accounting Document

    Accounting Document 原文:http://www.cnblogs.com/qiangsheng/archive/2007/12/12/991731.html Accounting d ...

  6. mysql5.7 本地计算机上的mysql 服务启动后停止 的问题解决

    mysql5.7 本地计算机上的mysql 服务启动后停止. 问题: 在cmd 下mysql服务mysql服务无法启动任何错误法启动 服务没有报告任何错误     在服务里面启动是   早上来了发现项 ...

  7. PHP | Uploading and reading of files and database 【PHP | 文件的上传和读取与数据库】

    这是我自己的一个作业,用的是很基础的代码. 有错误的地方欢迎批评和指正! 这里最容易出错的地方在读取数据后向数据库表中插入数据是的数据格式! 文件上传的页面 uploading.php <htm ...

  8. 使用Cygwin在WIN系统下处理文本常用命令

    1.打开Cygwin,把需要处理的文本复制你的安装目录例如:D:\cygwin\home\Administrator 使用 ls命令查看根目录文件 2.现在我们就可以对1.txt文本进行操作, 3.我 ...

  9. python实现归并排序,归并排序的详细分析

    python实现归并排序,归并排序的详细分析.   学习归并排序的过程是十分痛苦的.它并不常用,看起来时间复杂度好像是几种排序中最低的,比快排的时间复杂度还要低,但是它的执行速度不是最快的.很多朋友不 ...

  10. Centos6.5 安装python2.7.14

    2018-06-30 因为Centos6.5系统默认使用,python2.6.6.最近在学python.老师推荐将2.6.6升级至2.7.14.所以以留此文,怕哪天脑子短路好回来看看... >1 ...