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. RISC-V平台的汇编指令解析

     csrr    a0, 0xF14 //把0xF14的值读入到a0中  andi    a1, a0, 0x1f //把a0 和0x1F按位与运算后存储到a1中 srli    a0, a0, 5 ...

  2. 机器学习入门09 - 特征组合 (Feature Crosses)

    原文链接:https://developers.google.com/machine-learning/crash-course/feature-crosses/ 特征组合是指两个或多个特征相乘形成的 ...

  3. Robot Framework - 建立本地测试环境

    注意:本文内容是以“在Window7系统中安装本地RobotFrmamework自动化测试环境”为例. Robot Framework简介 HomePage:http://robotframework ...

  4. 开发十年,只剩下这套Java开发体系了 原

    蓦然回首自己做开发已经十年了,这十年中我获得了很多,技术能力.培训.出国.大公司的经历,还有很多很好的朋友.但再仔细一想,这十年中我至少浪费了五年时间,这五年可以足够让自己成长为一个优秀的程序员,可惜 ...

  5. Python编程Day7——字符编码、字符与字节、文件操作

    一.字符编码 重点 ***** 1. 什么是字符编码:将人识别的字符转换计算机能识别的01,转换的规则就是字符编码表2. 常用的编码表:ascii.unicode.GBK.Shift_JIS.Euc- ...

  6. .Net #if DEBUG调试模式代码使用

    #if DEBUG      Console.WriteLine("DEBUG:11111111111"); #else       Console.WriteLine(" ...

  7. python不同开根号速度对比

    import time import math import numpy as np def timeit1(): s = time.time() for i in range(750000): z= ...

  8. 浅尝Spring Cloud Sleuth

    Spring Cloud Sleuth提供了分布式追踪(distributed tracing)的一个解决方案.其基本思路是在服务调用的请求和响应中加入ID,标明上下游请求的关系.利用这些信息,可以方 ...

  9. Android中设置控件的背景颜色的方式整理

    版权声明:本文为博主原创文章,未经博主允许不得转载. 前言 在Android开发中,经常需要设置控件的背景颜色或者图片的src颜色. 效果图 代码分析 根据使用的方法不同,划分为 setBackgro ...

  10. 遇到的一些Jquery,js函数

     jQuery.extend()        jQuery.merge():函数用于合并两个数组内容到第一个数组. <script> $(function () { ,,], [,,] ...