Originariamente inviato da francesco.muia
di default prende la corrente directory del file class. Ovviamente se vuoi cambiare percorso lo puoi fare passando un FileOutputStream.
dici una cosa del genere:
codice:
public static synchronized void setProperty(String key, String value) {
Properties properties = new Properties();
try {
properties.load(new FileInputStream(fileProperties));
properties.setProperty(key, value);
} catch (IOException ex) {
JOptionPane.showMessageDialog(null, "Errore lettura file: " + fileProperties + "\nErrore: " + ex.getMessage());
}
try {
if (System.getProperty("os.name").contains("window")) {
properties.store(new FileOutputStream(System.getProperty("user.home") + "\\config.properties"), null);
} else {
properties.store(new FileOutputStream(System.getProperty("user.home") + "/config.properties"), null);
}
} catch (IOException ex) {
JOptionPane.showMessageDialog(null, "Errore salvataggio file: " + fileProperties + "\nErrore: " + ex.getMessage());
}
}