Monday, February 19, 2007

Read/Write Properties File

1 comment:

Contact: highbrow.admin@gmail.com said...

import java.util.Properties;
import java.io.*;

public class PropertiesClass{

public static void main(String[] args){


//Write properties file.
Properties wProperties = new Properties();
wProperties.put("HB","SW");
try {
wProperties.store(new FileOutputStream("myapp.properties"), null);
System.out.println(" Set value SW to the property name HB");
} catch (IOException e) {
e.printStackTrace();
}


//Read properties file.
Properties rProperties = new Properties();
try {
rProperties.load(new FileInputStream("myapp.properties"));
} catch (IOException e) {
e.printStackTrace();
}
String value = (String)rProperties.get("HB");
System.out.println(" This is the value of the property HB:"+ value);
}
}