How To Write Properties File In Java

Properties files are stored values in the key-value pairs. This tutorial explains how you can create the properties file using the Java program. If you are aware, Java itself has a Properties class which is used for string the values in the key-value pairs. If you have the values in the Properties object, then those values can be easily transferred to a FileOutputStream to create properties file. Lets look at a simple example to create properties file.


import java.util.Properties;

public class WritePropertiesFileExample {
	public static void main(String[] args) {
		try {
			Properties userProperties = new Properties();
			userProperties.setProperty("", "krishna");
			userProperties.setProperty("", "India");
			userProperties.setProperty("", "Bangalore");

			File userFile = new File("");
			FileOutputStream userFileOut = new FileOutputStream(userFile);, "User Details");
		} catch (FileNotFoundException e) {
		} catch (IOException e) {


If you run the above program, a file will be created with the content as below.

#User Details
#Mon Jan 27 06:46:14 IST 2014

Leave a Reply

Your email address will not be published. Required fields are marked *

Pin It on Pinterest

Share This

Share this post with your friends!