Example & Tutorial understanding programming in easy ways.

How to create and store property file dynamically in java?.

 We can also create property files dynamically. First create Properties object, add all property key-value pair by using setProperty() method. Then write this file to FileOutputStream object to store is as a property file. Below example shows how to create it.

Example:

package javatest.files;

import java.io.FileNotFoundException;

import java.io.FileOutputStream;

import java.io.IOException;

import java.io.OutputStream;

import java.util.Properties;

public class PropertyFiletest {

public static void main(String a[]) throws IOException{

OutputStream os = null;

Properties prop = new Properties();

prop.setProperty("name", "hellojava");

prop.setProperty("domain", "wwwr4r.in");

prop.setProperty("email", "r4r@gmail.com");

try {

os = new FileOutputStream("MyProp.properties");

prop.store(os, "Dynamic Property File");

} catch (FileNotFoundException e) {

e.printStackTrace();

}}}

Read More →