Here you can find the source of saveProperty(String key, String value)
public static void saveProperty(String key, String value)
//package com.java2s; //License from project: Apache License import java.io.File; 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 saveProperty(String key, String value) { Properties prop = getProperties(); OutputStream output = null; try {/* w w w . j ava 2 s . c o m*/ output = new FileOutputStream("config.properties"); // set the properties value prop.setProperty(key, value); // save properties to project root folder prop.store(output, null); } catch (IOException io) { io.printStackTrace(); } finally { if (output != null) { try { output.close(); } catch (IOException e) { e.printStackTrace(); } } } } private static Properties getProperties() { Properties prop = new Properties(); InputStream input = null; if (!new File("config.properties").exists()) return prop; try { input = new FileInputStream("config.properties"); // load a properties file prop.load(input); // get the property value and print it out return prop; } catch (IOException ex) { ex.printStackTrace(); } finally { if (input != null) { try { input.close(); } catch (IOException e) { e.printStackTrace(); } } } return prop; } }