private Properties getProperties() throws IOException { Properties p; File f; if ((f = Environment.getPropertiesFile(FManager.class)).exists()) { try (InputStream is = new FileInputStream(f)) { p = new Properties(); p.load(is); is.close(); } } else { throw new IOException("Cannot load properties."); } return p; }
public void saveSettings(Map<String, String> keyValMap, boolean autoLoad) throws IOException { Properties p; File f; if ((f = Environment.getPropertiesFile(FManager.class)).exists()) { this.activeFingerprintFileMap.clear(); try (InputStream is = new FileInputStream(f)) { p = new Properties(); // p.load(is); keyValMap .entrySet() .stream() .forEach( pair -> { p.setProperty(pair.getKey(), pair.getValue()); this.activeFingerprintFileMap.put( new File(pair.getKey()), Boolean.valueOf(pair.getValue())); }); p.setProperty(AUTOLOAD, autoLoad + ""); // is.close(); FileOutputStream fos = new FileOutputStream(f); p.store( fos, "Updated " + DateFormatUtils.format( System.currentTimeMillis(), ISO_EXTENDED_FORMAT_PATTERN, Locale.ENGLISH)); try { fos.close(); } catch (Exception ex) { } } } else { throw new IOException("Cannot store properties."); } }
public static void saveSetting(String key, String val) throws IOException { Properties p; File f; if ((f = Environment.getPropertiesFile(FManager.class)).exists()) { try (InputStream is = new FileInputStream(f)) { p = new Properties(); p.load(is); p.setProperty(key, val); is.close(); FileOutputStream fos = new FileOutputStream(f); p.store( fos, "Updated " + DateFormatUtils.format( System.currentTimeMillis(), ISO_EXTENDED_FORMAT_PATTERN, Locale.ENGLISH)); try { fos.close(); } catch (Exception ex) { } } } else { throw new IOException("Cannot store properties."); } }