write Properties - Android java.util

Android examples for java.util:Properties

Description

write Properties

Demo Code


//package com.java2s;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import java.util.Properties;

public class Main {
    public static void writeProperties(String filePath,
            String parameterName, String parameterValue) {
        Properties prop = new Properties();
        try {/*w w w.java  2  s .com*/
            InputStream fis = new FileInputStream(filePath);
            // 
            prop.load(fis);
            //  Hashtable ? put? getProperty ?
            // ? Hashtable  put 
            OutputStream fos = new FileOutputStream(filePath);
            prop.setProperty(parameterName, parameterValue);

            prop.store(fos, "Update '" + parameterName + "' value");
        } catch (IOException e) {
            System.err.println("Visit " + filePath + " for updating "
                    + parameterName + " value error");
        }
    }
}

Related Tutorials