Home Tutorial Java Core Files Java read properties file


Share on Google+Share on Google+
Java read properties file
Posted on: July 4, 2006 at 12:00 AM
In this section, you will learn how to read properties file.

Java read properties file

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

Description of code:

There are different tools to access different files. Now to load the data from the properties file, we have used Properties class. This class allowed us to save data to a stream or loaded from a stream using the properties file. In the properties file, data has been stored as a key value pair in the form of string.

load()- This method reads a property list (key and element pairs) from the input stream.

getProperty() - This method searches for the property with the specified key in the properties file.

Here is the data.properties:

address=Rohini, Delhi

Video tutorial of reading properties file in Java.

Here is the code:

import java.io.*;
import java.util.*;

public class ReadPropertiesFile {
	public static void main(String[] args) {
		Properties prop = new Properties();
		try {
			prop.load(new FileInputStream("C:/data.properties"));
			String name = prop.getProperty("name");
			String address = prop.getProperty("address");
			System.out.println("Name: " + name);
			System.out.println("Address: " + address);
		} catch (Exception e) {

Through the above code, you can read any properties file.


Name: RoseIndia
Address: Rohini, Delhi


Related Tags for Java read properties file:

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.

Posted on: July 4, 2006

Recommend the tutorial

Advertisements Advertisements