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工具代码的更多相关文章

  1. 【转】Java 读写Properties配置文件

    [转]Java 读写Properties配置文件 1.Properties类与Properties配置文件 Properties类继承自Hashtable类并且实现了Map接口,也是使用一种键值对的形 ...

  2. Java 读写Properties配置文件

    Java 读写Properties配置文件 JAVA操作properties文件 1.Properties类与Properties配置文件 Properties类继承自Hashtable类并且实现了M ...

  3. 使用JAVA读写Properties属性文件

     使用JAVA读写Properties属性文件 Properties属性文件在JAVA应用程序中是经常可以看得见的,也是特别重要的一类文件.它用来配置应用程序的一些信息,不过这些信息一般都是比较少的数 ...

  4. 用java读写properties文件的代码

    package com.LY; import java.io.BufferedInputStream; import java.io.FileInputStream; import java.io.F ...

  5. java读写properties配置文件不改变属性的顺序和注释

    先贴代码 import java.io.BufferedWriter; import java.io.File; import java.io.FileInputStream; import java ...

  6. java 读写properties (配置)文件

    Properties属性文件在Java应用程序中是经常可以看得见的,也是特别重要的一类文件.它用来配置应用程序的一些信息,不过这些信息一般都是比较少的数据,没有必要使用数据库文件来保存,而使用一般的文 ...

  7. java.util.Properties工具类

    import java.io.FileNotFoundException; import java.io.FileWriter; import java.io.IOException; import ...

  8. (转)Java 读写Properties配置文件

    原文:http://www.cnblogs.com/xudong-bupt/p/3758136.html 1.Properties类与Properties配置文件 Properties类继承自Hash ...

  9. Java读写.properties文件实例,解决中文乱码问题

    package com.lxk.propertyFileTest; import java.io.*; import java.util.Properties; /** * 读写properties文 ...

随机推荐

  1. 浅谈static关键字的四种用法

    1.修饰成员变量 在一个person类中,一个成员变量例如 String name,当new2个person()对象时候,这2个对象在堆的位置是不同的,给name赋值张三.李四,这两个对象的name是 ...

  2. Spring 静态代理+JDK动态代理和CGLIB动态代理

    代理分为两种:静态代理 动态代理 静态代理:本质上会在硬盘上创建一个真正的物理类 动态代理:本质上是在内存中构建出一个类. 如果多个类需要进行方法增强,静态代理则需要创建多个物理类,占用磁盘空间.而动 ...

  3. MyBatis别名与util类技能了解

    1.别名 在java中String类型就是String类型,但是在MyBatis中可不会识别java中的类型,在MyBatis中String类型的别名是'string',小写的String,或者也可以 ...

  4. Lock wait timeout exceeded

    MySQL事务锁问题-Lock wait timeout exceeded问题: 一次ios在请求接口响应时间超长,耗时几十秒才返回错误提示,后台日志中出现Lock wait timeout exce ...

  5. JS中部分不常用小功能记录

    1.serializeArray()在表单中使用,必须在form标签中,需要手机的元素要有name属性.源生JS将对象转成json   resulrMK = JSON.stringify(resulr ...

  6. C# 未能加载文件或程序集或它的某一个依赖项。需要强名称程序集

    Could not load file or assembly 'xxx.xxx.xxx, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null' ...

  7. java并发编程知识点备忘

    最近有在回顾这方面的知识,稍微进行一些整理和归纳防止看了就忘记. 会随着进度不断更新内容,比较零散但尽量做的覆盖广一点. 如有错误烦请指正~ java线程状态图 线程活跃性问题 死锁 饥饿 活锁 饥饿 ...

  8. 解决SVN不显示绿色图标问题

    今天是上班的第50天,发现项目上的svn绿色图标没有了,于是上网查了一下,然后很简单的就找到了解决办法: 修改注册表 Windows Explorer Shell支持Overlay Icon最多15个 ...

  9. js自定义对象和类

    1.工厂方式 <script type="text/javascript"> function createObject(name){        var p = n ...

  10. 基于阿里云 DNS API 实现的 DDNS 工具

    0.简要介绍 0.1 思路说明 AliDDNSNet 是基于 .NET Core 开发的动态 DNS 解析工具,借助于阿里云的 DNS API 来实现域名与动态 IP 的绑定功能.工具核心就是调用了阿 ...