How to use java Properties API -- read and write

原创 2005年03月03日 21:16:00

===========================Source Code============================================

package suncertify.utility;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.Properties;
import java.util.Set;
import java.util.logging.LogManager;

import suncertify.Constraints;
import suncertify.db.SystemException;

public class ConfiguraionUtil {
    public static final Properties readProperties()
            throws SystemException {
        Properties properties = new Properties();
        try {
            properties.load(new FileInputStream(
                    new File(Constraints.FILE_PROPERTIES)));
        } catch (FileNotFoundException e) {
            throw new SystemException(
                    "Can not find the suncertify.properties file");
        } catch (IOException e) {
            throw new SystemException("I/O error occurs when reading the file");
        }
        return properties;
    }

    public static final void writeProperties(final Hashtable table)
            throws SystemException {
        Properties properties = new Properties();
        FileOutputStream out = null;
        try {
            Set keys = table.keySet();
            Iterator iter = keys.iterator();
            String content = "";
            while (iter.hasNext()) {
                String key = (String) iter.next();
                Object value = table.get(key);
                content += key + "=" + value + "/n";
            }
            out = new FileOutputStream(new File(Constraints.FILE_PROPERTIES));
            out.write(content.getBytes());
            properties.store(out, null);
        } catch (FileNotFoundException e) {
            throw new SystemException(
                    "Can not find the suncertify.properties file");
        } catch (IOException e) {
            throw new SystemException("I/O error occurs when reading the file");
        } finally {
            try {
                out.close();   
            } catch(IOException e) {
                out = null;
            }
        }
    }

}

Reference:

http://www.dimi.uniud.it/labs/documentazione/java1.0-tutorial/java/cmdLineArgs/properties.html

http://javaalmanac.com/egs/java.util/Props.html

JavaAndroid客户端和C#服务端Web Api接口开发

C#服务端HttpGet接口开发 C#服务端HttpPost接口开发 JavaAndroid客户端请求C#服务端HttpGet接口开发 JavaAndroid客户端Android请求C#服务端HttpPost接口开发
  • 2017年01月08日 20:05

《深入理解java虚拟机》之内存模型与安全

不同的平台,内存模型是不一样的,但是jvm的内存模型规范是统一的。其实java的多线程并发问题最终都会反映在java的内存模型上,所谓线程安全无非是要控制多个线程对某个资源的有序访问或修改。总结jav...
  • sjtu_chenchen
  • sjtu_chenchen
  • 2015-10-14 22:11:07
  • 1231

java_USB_API

  • 2017年04月02日 10:00
  • 1.58MB
  • 下载

Read / Write Excel file in Java using Apache POI

转自: http://viralpatel.net/blogs/java-read-write-excel-file-apache-poi/ Read / Write Excel f...
  • jollypigclub
  • jollypigclub
  • 2015-06-30 15:31:20
  • 929

java - properties read write

架构: Get properties: public static Properties getProperties(String fileName) { String filePath...
  • textboy
  • textboy
  • 2015-08-27 10:25:42
  • 342

Getting Started with Google Guava

  • 2017年10月03日 12:22
  • 1.3MB
  • 下载

Sample of C++ read/write a text file

#include #include using namespace std;int main(){    const char *filename = "t.txt";    ofstream ofi...
  • HiHui
  • HiHui
  • 2009-06-05 17:16:00
  • 1809

Linux系统调用及用户编程接口(API) open close write read lseek

系统调用:操作系统提供给用户程序调用的一组“特殊接口,可以通过这组接口获得操作系统内核提供的服务。例如:创建进程、实现进程调度、进程管理,进程间通信,文件系统控制,系统控制,存储管理,网络管理,soc...
  • lyk314949530
  • lyk314949530
  • 2017-05-24 20:35:15
  • 369

FPGA 使用Active-HDL仿真时出现Cannot access SLP signal `/clk'. Use switch +access +r for this region.

如题# KERNEL: Warning: Cannot access SLP signal `/clk'. Use switch +access +r for this region. 解决方法: ...
  • zmq5411
  • zmq5411
  • 2012-07-20 11:50:58
  • 1935

jpeg图像压缩。。。。。。。

  • 2009年06月08日 16:01
  • 394KB
  • 下载
收藏助手
不良信息举报
您举报文章:How to use java Properties API -- read and write
举报原因:
原因补充:

(最多只允许输入30个字)