Properties erweitern

Allrounder93

Aktives Mitglied
moin,

ich habe folgenden Code mir zusammen gesucht...^^
Leider wird die datei als überspeichert, statt erweitert...?! Wo liegt der Fehler :rtfm:

Java:
		standartItems("source","c:/",true);
		standartItems("destination","d:/",true);

Danach steht in der datei nur destination=d:/ und nicht "source=c:/ destination=d:/" :autsch:

Java:
	private static String standartItems(String typ, String worth, Boolean RorW) throws IOException{
		if (PropertiesPath.exists() == false) {PropertiesPath.createNewFile();}					//legt Datei an
		
		Properties props = new Properties();
		FileInputStream in = new FileInputStream(PropertiesPath);				//öffnet Propertie Datei
		
		if (RorW == true){														//Schreibt Werte in Datei
			props.setProperty(typ, worth);
			FileOutputStream out = new FileOutputStream(PropertiesPath);
			props.store(out, null);
			return null;
			
		} else {																//Ließt Datei und gibt werte aus
			props.load(in);
			in.close();
			String str = props.getProperty(typ);
			return str;
		}
	}
 
Java:
FileOutputStream out = new FileOutputStream(PropertiesPath, true);

Siehe FileOutputStream (Java Platform SE 7 )

Btw.: Einen close für die FileOutputStream's solltest du auch einbauen. EInfach nur aufreißen und nie zu machen ist nicht wirklich schön...
 
Zuletzt bearbeitet:
Wunderbar! Vielen dank :applaus:

Jedoch sammeln sich nun Var dooeplt, ich dachte eigentlich, das die vorhandene Var überspeichert wird...
Und muss ich echt jedesmal prüfen ob die Datei vorhanden ist oder kann das nicht auch mit einen einfach true übernommen werden^^
 

Zurück
Oben