Sunday, 19 February 2012

Reading properties file java

Reading properties file in java:

Properties file in java is a simple key value file where key and value is separated by  '='.

Below example reads properties files and displays all the elements in it. is a property file.
#configuration properties
PropertyReader reades the

package demo;

import java.util.Properties;
 * Reads properties file and display all the contents in it
 * @author luckyacademy
public class PropertyReader {
 public static void main(String[] args) throws Exception {
  //open input stream to properties file
  FileInputStream fin = new FileInputStream("");
  Properties pr = new Properties();
  // read properties file
  //read value for key username
  System.out.println("Reading value: " + pr.getProperty("username"));

  //display all properties in file.
  for(Object key:pr.keySet()){
   System.out.println("Key: "+key+ " Value: "+pr.getProperty((String)key));
  //close the properties file

No comments:

Post a Comment