Share on Google+Share on Google+

Java Write to properties file

In this section, you will learn how to write data to properties file.

Java Write to properties file

In this section, you will learn how to write data to properties file.

 The properties file is basically used to store the configuration data or settings.It stores the data in key-value pair. Java has provide Properties class to store data into .properties file. It consists of a hashtable data structure of String keys with a String value for each key. Here we are going to create a .properties file and write data to it in the form of key-value.

In the given example, we have created an object of Properties class and put three key/value pairs within the Properties object using the setProperty() method.  The store method of the Properties class is then store the Properties object to the file.


import java.util.*;

public class WritePropertiesFile {
	public static void main(String[] args) {
		try {
			Properties properties = new Properties();
			properties.setProperty("Natinal-Animal", "Tiger");
			properties.setProperty("Natinal-Flower", "Lotus");
			properties.setProperty("National-Bird", "Peacock");

			File file = new File("");
			FileOutputStream fos = new FileOutputStream(file);, "");
		} catch (FileNotFoundException e){
		} catch (IOException e) {


#Wed Sep 26 16:56:26 IST 2012



Posted on: September 26, 2012 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.