Get All Keys and Values of the Properties files in Java

In this section, you will learn how to get all keys and it's values of the properties files in Java.

Ads

Tutorials   
How to read properties file in Java? Generate random numbers in Java Cloneable Interface in Java What is the flaw with the Stack class? List In Java Java Stack Example HashSet In Java Enumeration in java How to generate random number in java Iterator in java Queue in java Transient Java Keyword clone method in Java Java Queue example Logger in Java Java current date - How to get current date in Java Collection : LinkedList Example Collection : ArrayList Example Random alpha numeric string of fixed size Java List Iterator Example The Hashtable Class The BitSet class Java Vector Java Enumeration Data Structures in Java Java Transient Variable Java Date Format Example Java Properties File Example Map.Entry Java Interface Java Property File java preferences,Change the value of Preferences by user Retrieving a Preference Node Java hasNext Write Keys and Values to the Properties file in Java Get All Keys and Values of the Properties files in Java Properties file in Java Properties file in Java Determining If a Preference Node Contains a Specific Value Change the value of Preferences by user Clone method example in Java Implementing a Simple Event Notifier Determining When a Preference Node Is Added or Removed Listening for Changes to Preference Values in a Preference Node Importing Preferences Finding a Preference in a Preference Tree Retrieving the Parent and Child Nodes of a Preference Node Determining If a Preference Node Exists Removing a Preference Node Creating a Preference Node Getting the Maximum Size of a Preference Key and Value
Ads

Get All Keys and Values of the Properties files in Java

     

In this section, you will learn how to get all keys and it's values of the properties files in Java. Java provides the features to collection of all keys and values of the properties file. The properties files that can be used to large collections of information to be inserting in the properties files.

Here, you will get the all keys and values of the properties files with the help of this program. The program shows the keys and it's values when you run it. The following methods had been used by the program.

pro.keySet():
This method returns a set of keys, which contained in the object of the Properties method. The Properties files has the many keys then this method provides all keys.

pro.keys():
This method provides the all keys of the properties files. Which stored in the Enumeration objects.

Enumeraton:
This is the interface which provided by the java.util package. It's object implements the series of elements and calls the nextElements method, which provides the series of elements. The keys and values of the Properties files which is enumerated by this interface and calls the hashtable which defines the keys and values of the properties files.

hasMoreElements():
This method checks the Enumeration object has more elements or not and returns the true or false. It returns true, if the Enumeration object has more than one elements Otherwise, it return false.

nextElement():
This is the method to returns the next elements of the Enumeration, if the enumeration provides the more than one elements.

Here is the video tutorial of: "How to get key and value from properties file in Java?"

 

Here is the code of program:

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

public class GetAllProperties{
  public static void main(String[] args){
  Properties pro = new Properties();
  try{
  BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  System.out.print("Enter file name for getting all properties : ");
  FileInputStream in = new FileInputStream(br.readLine() ".properties");
  pro.load(in);
  System.out.println("All keys of the property file : ");
  System.out.println(pro.keySet());
  System.out.println("All values of the property file : ");
  Enumeration em = pro.keys();
  while(em.hasMoreElements()){
  String str = (String)em.nextElement();
  System.out.println(str + ": " + pro.get(str));
  }
  }
  catch(IOException e){
  System.out.println(e.getMessage());
  }
  }
}

Download this example

 

Advertisements

Share on Google+Share on Google+

Get All Keys and Values of the Properties files in Java

Posted on: April 16, 2007 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Advertisements

Ads
 

Discuss: Get All Keys and Values of the Properties files in Java   View All Comments

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:1
Ducky
January 16, 2012
njasNEKfcDvCAEBVd

Thanky Thanky for all this good informtoain!

Ads

 

Ads