package My; import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; import java.util.Properties; public class PropertiesUtils { static String proPath = "src/my/conf.properties"; static Properties pro = null; static ArrayList list = new ArrayList(); HashMap map = new HashMap(); static public void ReadProperties() { pro = new Properties(); FileInputStream in; try { in = new FileInputStream(proPath); pro.load(in); in.close(); } catch (IOException e) { e.printStackTrace(); } } static public void WriteProperties(String key, String value) { try { FileOutputStream oFile = new FileOutputStream(proPath, false);// true表示追加打开 pro.setProperty(key, value); pro.store(oFile, "test"); oFile.close(); } catch (IOException e) { e.printStackTrace(); } } public static void main(String[] args) { ReadProperties(); WriteProperties("城市", "洛阳"); } }