CodesJava

Easy learning with example program codes

create and store property file dynamically java

Example:

package com.codesjava;
 
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.util.Properties;
 
public class PropertyFileTest {
  public static void main(String args[]){
      OutputStream os = null;
      Properties prop = new Properties();
      prop.setProperty("name", "codesjava");
      prop.setProperty("domain", "www.codesjava.com");
      prop.setProperty("email", "hr@codesjava.com");
      try {
          os = new FileOutputStream("TestProp.properties");
          prop.store(os, "Dynamic Property File");
          System.out.println("Property file created successfully.");
      } catch (Exception e) {
          e.printStackTrace();
      }
  }
}

Output:

TestProp.properties

#Dynamic Property File
#Sat Mar 17 16:13:03 IST 2018
email=hr@codesjava.com
name=codesjava
domain=www.codesjava.com

Download this example.

Please follow and like us:
error
Posted in IO   








Copyright © 2019 CodesJava DMCA.com Protection Status