---
title: "一个Property文件封装类"
author: "java1573"
date: "2007-08-10T13:51:04Z"
tags: []
slug: "property"
draft: false
lastmod: "2007-08-10T13:51:04Z"
id: 110859
url: "https://java1573.iteye.com/blog/110859"
---

**PropertyFile.java**

package tools;

 

import ……

 

/\**

 * 功能：工具函数，封装对属性文件的操作

 * @author LOVO

 \*/

public class PropertyFile {

       //私有属性成员

       private Properties prop;

       private String fileName;

 

       //初始化:指定文件名

       public PropertyFile(String \_fileName){

              prop = new Properties();

              this.fileName = \_fileName;

              load();

       }

       //读取文件到内存

       public void load(){

              prop.load(new FileInputStream(this.fileName));

       }

       //保存文件到磁盘中

       public boolean save(){

              prop.store(new FileOutputStream(this.fileName),null);

       }

       //读取鍵值

       public String getKeyValue(String \_key){

              String value = prop.getProperty(\_key);

       }

       //设置鍵值

       public void setKeyValue(String \_key,String \_value){

              prop.setProperty(\_key, \_value);

       }

}