Ich habe ein kleines Programm geschrieben - funktioniert so weit gut. Nur bin ich gerade am Verzweifeln was properties angeht. Habe schon viel Zeit in Recherchen investiert - leider ohne Erfolg.
Ich habe folgendes Probelm: Das Lesen und und Schreiben von Properties funktioniert gut wenn ich es direkt in eclipse starte. Sobald ich ein JAR erzeuge, geht nur das Lesen.
prop = new Properties();
Schreiben in der Classe B (nach Button-Betätigung):
void saveConfiguration(ActionEvent e) {
try {
//set the properties value
prop.setProperty("fPathPPT", txtDirectory.getText());
prop.setProperty("fPathLogger", txtFieldPathLogger.getText());
//save properties to project root folder
prop.store(new FileOutputStream("config.properties"), null);
} catch (IOException ex) {
ex.printStackTrace();
}
dispose();
}
Lesen in der Classe A
try {
props = new Properties();
props.load(new FileInputStream("config.properties"));
fPath=props.getProperty("fPathPPT");
fPathLogger=props.getProperty("fPathLogger");
}
catch (java.io.IOException clientException) {
JOptionPane.showConfirmDialog(this, "Error: " +
clientException, "Einstellungen für FileSelectorAndLogger",
JOptionPane.DEFAULT_OPTION,
JOptionPane.WARNING_MESSAGE);
}
; // end catch
Zwecks Debugging habe ich zwei Properties-Dateien angelegt um das Verhalten auszuprobieren, siehe Abbildung.
Wäre sehr fro wenn mir jemand helfen könnte.
Grüße, Andreas
Ich habe folgendes Probelm: Das Lesen und und Schreiben von Properties funktioniert gut wenn ich es direkt in eclipse starte. Sobald ich ein JAR erzeuge, geht nur das Lesen.
prop = new Properties();
Schreiben in der Classe B (nach Button-Betätigung):
void saveConfiguration(ActionEvent e) {
try {
//set the properties value
prop.setProperty("fPathPPT", txtDirectory.getText());
prop.setProperty("fPathLogger", txtFieldPathLogger.getText());
//save properties to project root folder
prop.store(new FileOutputStream("config.properties"), null);
} catch (IOException ex) {
ex.printStackTrace();
}
dispose();
}
Lesen in der Classe A
try {
props = new Properties();
props.load(new FileInputStream("config.properties"));
fPath=props.getProperty("fPathPPT");
fPathLogger=props.getProperty("fPathLogger");
}
catch (java.io.IOException clientException) {
JOptionPane.showConfirmDialog(this, "Error: " +
clientException, "Einstellungen für FileSelectorAndLogger",
JOptionPane.DEFAULT_OPTION,
JOptionPane.WARNING_MESSAGE);
}
; // end catch
Zwecks Debugging habe ich zwei Properties-Dateien angelegt um das Verhalten auszuprobieren, siehe Abbildung.
Wäre sehr fro wenn mir jemand helfen könnte.
Grüße, Andreas