java读写properties工具代码
package test612;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Properties;
public class Tool {
public static String read(String key){
String dd = null;
Properties prop = new Properties();
InputStream fis = null;
String rootPath = System.getProperty("user.dir").replace("\", "/");
try {
File file = new File(rootPath+"/house.properties");
if (!file.exists())
file.createNewFile();
fis = new FileInputStream(rootPath+"/house.properties");
prop.load(fis);
fis.close();//一定要在修改值之前关闭fis
dd=prop.getProperty(key);
} catch (IOException e) {
}
finally{
try {
fis.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return dd;
}
public static void write(String key,String value){
Properties prop = new Properties();
String rootPath = System.getProperty("user.dir").replace("\\", "/");
OutputStream os = null;
try {
prop.setProperty(key, value);
try {
os = new FileOutputStream(rootPath+"/house.properties",true);
prop.store(os, "comments for main2");
os.flush();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
finally{
try {
os.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
public static void main(String[] args) {
}
}
java读写properties工具代码的更多相关文章
- 【转】Java 读写Properties配置文件
[转]Java 读写Properties配置文件 1.Properties类与Properties配置文件 Properties类继承自Hashtable类并且实现了Map接口,也是使用一种键值对的形 ...
- Java 读写Properties配置文件
Java 读写Properties配置文件 JAVA操作properties文件 1.Properties类与Properties配置文件 Properties类继承自Hashtable类并且实现了M ...
- 使用JAVA读写Properties属性文件
使用JAVA读写Properties属性文件 Properties属性文件在JAVA应用程序中是经常可以看得见的,也是特别重要的一类文件.它用来配置应用程序的一些信息,不过这些信息一般都是比较少的数 ...
- 用java读写properties文件的代码
package com.LY; import java.io.BufferedInputStream; import java.io.FileInputStream; import java.io.F ...
- java读写properties配置文件不改变属性的顺序和注释
先贴代码 import java.io.BufferedWriter; import java.io.File; import java.io.FileInputStream; import java ...
- java 读写properties (配置)文件
Properties属性文件在Java应用程序中是经常可以看得见的,也是特别重要的一类文件.它用来配置应用程序的一些信息,不过这些信息一般都是比较少的数据,没有必要使用数据库文件来保存,而使用一般的文 ...
- java.util.Properties工具类
import java.io.FileNotFoundException; import java.io.FileWriter; import java.io.IOException; import ...
- (转)Java 读写Properties配置文件
原文:http://www.cnblogs.com/xudong-bupt/p/3758136.html 1.Properties类与Properties配置文件 Properties类继承自Hash ...
- Java读写.properties文件实例,解决中文乱码问题
package com.lxk.propertyFileTest; import java.io.*; import java.util.Properties; /** * 读写properties文 ...
随机推荐
- MngoDb MongoClientOptions 配置信息及常用配置信息
MongoClientOptions.Builder addClusterListener(ClusterListener clusterListener)Adds the given cluster ...
- 使用freemarker生成xml模板
今天在java交流群里有个人问我如何用freemarker生成xml模板文件,可以手动配置参数,于是我到网上百度了一下.发现有一位同行的博文写的很nice,于是我就照着他的代码敲了一遍,最后实现了,本 ...
- Chapter 4 Invitations——3
Edward was never surrounded by crowds of curious by standers eager for his firsthand account. Edward ...
- Centos7搭建邮件服务器-Postfix+Cyrus-sasl+Courier-authlib+Dovecot+ExtMail+Centos7
1.环境介绍 MTA: Postfix 3.1.4 SASL: Cyrus-sasl 2.1.26 ; Courier-authlib 0.66.1(Cyrus-sasl使用Courier-authl ...
- 菜鸟系列docker——docker镜像下(5)
1. docker镜像构建 该章节主要介绍2种构建docker镜像的方式.当然,当前基本上需要的基础镜像都有,直接使用即可.例如数据库.中间件之类的,只需要拿来使用即可,但是依然存在需要开发者构建镜像 ...
- docker 构建 https 私有仓库 Registry
1.安装docker # docker install docker 2.拉取仓库镜像 # docker pull registry 3.生成认证certificate # mkdir ~/certs ...
- spring jdbcTemplate 事务,各种诡异,包你醍醐灌顶!
前言 项目框架主要是spring,持久层框架没有用mybtis,用的是spring 的jdbc: 业务需求:给应用添加领域(一个领域包含多个应用,一个应用可能属于多个领域,一般而言一个应用只属于一个领 ...
- Ansible剧本介绍及使用演示(week5_day2)--技术流ken
Ansible剧本编写说明 一. 缩进 yaml 的缩进要求比较严格.一定不能使用tab键 注意:编写yaml文件,就忘掉shell的tab吧. 二. 冒号 每个冒号后面一定要有一个空格 注意:1. ...
- HDUOJ-2089 不要62
Problem Description 杭州人称那些傻乎乎粘嗒嗒的人为62(音:laoer). 杭州交通管理局经常会扩充一些的士车牌照,新近出来一个好消息,以后上牌照,不再含有不吉利的数字了,这样一来 ...
- 从零开始学安全(十四)●Windows Server 2012 R2 本地搭建FTP服务器
打开仪表盘添加角色和功能向导 下一步 等待安装完成 打开iis 新建站点 点击 选一个目录作为 ftp文件服务器的存储路径 后面就和iis 创建站点一样了 匿名就不需要密码 就可以访问基本需要特定的账 ...