Tutorialspoint examples

Learn java tutorial with examples for beginners online

create and store property file dynamically java


Example:

package com.tutorialspointexamples;
 
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", "tutorialspointexamples");
      prop.setProperty("domain", "www.tutorialspointexamples.com");
      prop.setProperty("email", "tutorialspointexamples@gmail.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=tutorialspointexamples@gmail.com
name=tutorialspointexamples
domain=www.tutorialspointexamples.com

Download this example.

Download tutorialspointexamples Android App
Copyright © 2018 Tutorialspoint examples DMCA.com Protection Status