Core Java| JSP| Servlets| XML| EJB| JEE5| Web Services| J2ME| Glossary| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest Questions
Comments
 
 
 


 

Get All Keys and Values of the Properties files in Java

                         

In this section, you will learn how to get all keys and values of the properties files in the Java. This section illustrates the way for getting all keys and corresponding values of the properties file through an example. The example is given bellow.

Description of program:

Here, you will get all keys and values of the properties files with the help of this program. The program shows the keys and values when you run it. 

The following methods are explained as follows which have been used in the program.

pro.keySet():
This method returns a set of keys, which contains in the Properties method.

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

Enumeraton:
It's the interface provided by the java.util package. Enumeration implements a series of elements and calls the nextElements method, which provides a series of elements. The keys and values of the properties files that are enumerated in this interface calls by hashtable, which defines the keys and values of the properties files.

hasMoreElements():
This method checks the Enumeration that has one more elements or not with returns true or false. If it returns true, then the Enumeration object has more than one element, otherwise it return false.

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

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{
      FileInputStream in = new FileInputStream("Message.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(pro.get(str));
      }
    }
    catch (IOException e){
      System.out.println(e.getMessage());
    }
  }
}

Download this example.

 

                         

» View all related tutorials
Related Tags: java c file ide files properties io vi key value read this id for ie example values to learn exam

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Training Courses
Tell A Friend
Your Friend Name
Software Solutions
Least Viewed
Most Rated
Recently Viewed
Search Tutorials

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.