The following Class create a .properties file.
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Properties;
public class WritePropertyFile {
public static void main(String[] args) {
Properties prop = new Properties();
try {
// Write the properties value
prop.setProperty("name", "Eureka");
prop.setProperty("url", "https://ykyuen.wordpress.com");
// Save the changes
prop.store(new FileOutputStream("src/main/resources/config.properties"), null);
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
This is the output config.properties
#Sat Aug 27 23:02:57 CST 2011 url=http\://ykyuen.wordpress.com name=Eureka
Done =)
Next Post: Java – Read .properties
Reference: Mkyong.com – Java Properties file examples

One thought on “Java – Write .properties”