16 Mayıs 2008 Cuma

Reading and writing a properties file

Sometimes we need to read and write some data for remembering purposes to the outside of our project jar/war file.



I wrote some methods to achive these needs.
private Properties readFromPropertiesFile() {
// Read properties file.
Properties prop = new Properties();

try {
prop.load(new FileInputStream("data.properties"));

} catch (IOException e) {
}
return prop;
}



private void writeToPropertiesFile(Properties prop) {
// Write properties file.
try {
prop.store(new FileOutputStream("data.properties"), null);
} catch (IOException e) {
}
}


private String readKey(Properties prop, String key)
{
return prop.getProperty(key);
}



private void writeKey(Properties prop, String key, String value)
{
prop.setProperty(key, value);
}

Hiç yorum yok: