@Test public void testSave() throws Exception { Map<String, String> map = PropertiesHelper.readProperties(propertiesFile); Assert.notNull(map); map.put("aaa", "test"); PropertiesHelper.save(map, propertiesFile); Map<String, String> map2 = PropertiesHelper.readProperties(propertiesFile); String aaa = map2.get("aaa"); Assert.hasText(aaa); }
public static void save(Map<String, String> map, File file) throws IOException { Assert.notNull(map, "属性集合为空！"); Properties properties = new Properties(); Set<Map.Entry<String, String>> entries = map.entrySet(); for (Map.Entry<String, String> entry : entries) { String key = entry.getKey(); String value = entry.getValue(); properties.setProperty(key, value); } save(properties, file); }
PropertiesHelper { public static void save(Map<String, String> map, File file) throws IOException { Assert.notNull(map, "属性集合为空！"); Properties properties = new Properties(); Set<Map.Entry<String, String>> entries = map.entrySet(); for (Map.Entry<String, String> entry : entries) { String key = entry.getKey(); String value = entry.getValue(); properties.setProperty(key, value); } save(properties, file); } }
PropertiesHelper { public static void save(Map<String, String> map, File file) throws IOException { Assert.notNull(map, "属性集合为空！"); Properties properties = new Properties(); Set<Map.Entry<String, String>> entries = map.entrySet(); for (Map.Entry<String, String> entry : entries) { String key = entry.getKey(); String value = entry.getValue(); properties.setProperty(key, value); } save(properties, file); }  }
PropertiesHelper { public static void save(Map<String, String> map, File file) throws IOException { Assert.notNull(map, "属性集合为空！"); Properties properties = new Properties(); Set<Map.Entry<String, String>> entries = map.entrySet(); for (Map.Entry<String, String> entry : entries) { String key = entry.getKey(); String value = entry.getValue(); properties.setProperty(key, value); } save(properties, file); }  static Map<String, String> readProperties(String propertiesFilePath); static Map<String, String> readProperties(File propertiesFile); static Map<String, String> readProperties(InputStream inputStream); static void save(Map<String, String> map, File file); static void save(Properties properties, File file); static void main(String[] args); }
PropertiesHelper { public static void save(Map<String, String> map, File file) throws IOException { Assert.notNull(map, "属性集合为空！"); Properties properties = new Properties(); Set<Map.Entry<String, String>> entries = map.entrySet(); for (Map.Entry<String, String> entry : entries) { String key = entry.getKey(); String value = entry.getValue(); properties.setProperty(key, value); } save(properties, file); }  static Map<String, String> readProperties(String propertiesFilePath); static Map<String, String> readProperties(File propertiesFile); static Map<String, String> readProperties(InputStream inputStream); static void save(Map<String, String> map, File file); static void save(Properties properties, File file); static void main(String[] args);  }