ok ho un problemino:
codice:
public class Property {
private static String fileProperties = "config.properties";
public static synchronized String getString(String key) throws IOException {
String result = "";
Properties props = new Properties();
props.load(new FileInputStream(fileProperties));
result = props.getProperty(key);
return result;
}
public static synchronized void setProperty(String key, String value) throws IOException {
Properties properties = new Properties();
properties.load(new FileInputStream(fileProperties));
properties.setProperty(key, value);
if (System.getProperty("os.name").contains("window")) {
properties.store(new FileOutputStream(System.getProperty("user.home") + "\\" + fileProperties), null);
} else {
properties.store(new FileOutputStream(System.getProperty("user.home") + "/" + fileProperties), null);
}
}
}
richiamo il metodo:
codice:
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
try {
Property.setProperty("ciao", "core");
} catch (FileNotFoundException ex) {
JOptionPane.showMessageDialog(null, ex.getMessage());
} catch (IOException ex) {
JOptionPane.showMessageDialog(null, ex.getMessage());
}
}
il file c'è però mi compare sempre l'errore:
config.properties (No such file o directory).