Ho provato a salvare le proprietà e restituirle ma dove ho sbagliato? thanks
codice:
class App {
public void main(String[] args) {
Properties prop = new Properties();
Properties prop1 = new Properties();
Properties prop2 = new Properties();
Properties prop3 = new Properties();
OutputStream output = null;
try {
output = new FileOutputStream("config.properties");
// Imposta il valore di proprietà
prop.getProperty(textCLIENTE.getText());
prop1.getProperty(textNUM.getText());
prop2.getProperty(textMAIL.getText());
prop3.getProperty(textVIA.getText());
// Salvare le proprietà di proiettare cartella principale
prop.store(output, null);
prop1.store(output, null);
prop2.store(output, null);
prop3.store(output, null);
} catch (IOException io) {
io.printStackTrace();
} finally {
if (output != null) {
try {
output.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}
class App1 {
public void main(String[] args) {
App1 app = new App1();
app.printThemAll();
}
private void printThemAll() {
Properties prop = new Properties();
InputStream input = null;
try {
String filename = "config.properties";
input = getClass().getClassLoader().getResourceAsStream(filename);
if (input == null) {
System.out.println("Sorry, unable to find " + filename);
return;
}
prop.load(input);
Enumeration<?> e = prop.propertyNames();
while (e.hasMoreElements()) {
String key = (String) e.nextElement();
String value = prop.getProperty(key);
System.out.println("Key : " + key + ", Value : " + value);
}
} catch (IOException ex) {
ex.printStackTrace();
} finally {
if (input != null) {
try {
input.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}