package com.usr.io;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.util.Properties;
public class WritePropertiesFile {
public static void main(String[] args) {
try{
Properties pr=new Properties();
pr.setProperty("name","usr");
pr.setProperty("age","26");
pr.setProperty("city","bangalore");
File file=new File("test.properties");
FileOutputStream fos=new FileOutputStream(file);
BufferedWriter bw=new BufferedWriter(new OutputStreamWriter(fos));
//Writes this property list (key and element pairs) in this
Properties
table to the output character stream in a format suitable for using the load(Reader)
method. pr.store(bw,"userInfo");
bw.close();
}
catch(IOException ex){
ex.printStackTrace();
}
}
}
output
test.properties
#userInfo
#Tue Feb 21 19:58:00 IST 2012
age=26
name=usr
city=bangalore
#Tue Feb 21 19:58:00 IST 2012
age=26
name=usr
city=bangalore