Java - general

read and write properties

java.util.Properties
In a property-file (a normal textfile with the ending „properties“) information in the form

info=Huhu

can be saved.



The reading of a properties-file and the finish reading of an properties works as follows:

Properties props = new Properties();
FileInputStream in = new FileInputStream("c:\\JavaWiki\\MyProperties.properties");
props.load(in);
in.close();
String str = props.getProperty("info");
System.out.println(str);   // Here an "Huhu" is handed out.


Of course, you can also put properties and safe the property-file again:

props.setProperty("info", "Hello");   // "Huhu" is replaced by "Hello"
FileOutputStream out = new FileOutputStream("c:\\JavaWiki\\MyProperties.properties");
props.store(out, null);


After the safing the property-file would look like this:

info=Hello

Eigene Werkzeuge
Werkzeuge

gratis Counter by GOWEB
seit 9.10.2007