Manage a config file.

Hello all,

I'm writing a small application and I'll need to store configuration into a text file. I'd like to have a format like the .ini files under Windows:

[font]

name=Arial

size=10

color=123

[editor]

tabspace=8

Do you have any advice concerning that ? Would it be easy to it using XML ?

Thank you.

[372 byte] By [Morgoth_Sauron] at [2007-9-26 3:10:25]
# 1
Check out the Properties (JDK 1.3 and back) and the Preferences (JDK 1.4) classes.
schillj at 2007-6-29 11:16:55 > top of Java-index,Archived Forums,Java Programming...
# 2

This is what u need buddy!!!

java.util.Properties prop = new java.util.Properties();

java.io.FileInputStream in = new java.io.FileInputStream("test.properties");

prop.load(in);

System.out.println(prop.getProperty("prop1"));

System.out.println(prop.getProperty("prop2"));

System.out.println(prop.getProperty("prop3"));

System.out.println(prop.getProperty("prop4"));

java.util.Properties prop1 = new java.util.Properties();

java.io.FileOutputStream out = new java.io.FileOutputStream("test11.properties");

prop1.setProperty("prop2", "opopop");

prop1.setProperty("prop7", "55555555555555555");

prop1.store(out,"tetetest");

and ur "test.properties" file may contain for ex: foll lines:

prop1=aaa

prop2=aaa

prop3=aaa

prop4=aaa

Pramod

pramod_bs at 2007-6-29 11:16:55 > top of Java-index,Archived Forums,Java Programming...
# 3
use the new prefrences api in the new 1.4sdk, it is easily implementable. just check the documentation.
haroldsmith at 2007-6-29 11:16:55 > top of Java-index,Archived Forums,Java Programming...
# 4
Thank you all. I'll take a look to theses classes.
Morgoth_Sauron at 2007-6-29 11:16:55 > top of Java-index,Archived Forums,Java Programming...