Create and write to the properties file using java code.

Below java code snippet will create a new property file and write the properties into it.

import java.util.Properties;

public class WriteProperty {
    public static void main(String[] args) {
        Properties property = new Properties();
        try {
            // set the properties values
            property.setProperty("url", "host IP Address");
            property.setProperty("username", "Amzi");
            property.setProperty("password", "passw0rd");

            // save properties to project root folder
   FileOutputStream(""), null);
            .print("properties are saved into the destination folder");

        } catch (IOException e) {


properties are saved into the destination folder file should look something like this:

#Fri Aug 23 11:49:29 EDT 2013
url=host IP Address

1 comment:

  1. Thanks for the post, I am techno savvy. I believe you hit the nail right on the head. I am highly impressed with your blog. It is very nicely explained. Your article adds best knowledge to our Java Online Training from India. or learn thru Java Online Training from India Students.

    or learn thru JavaScript Online Training from India. Appreciating the persistence you put into your blog and detailed information you provide. Kindly keep blogging.