Home | Ajax | BioInformatics | Dojo | EAI | EJB | Hibernate | J2ME | Java | Java Glossary | Java Servlets | JavaScript | Jboss | JDBC | JDO | Jmeter | JSF | JSP | JUnit | Maven | MySQL | Spring Framework | SQL | Struts | Technology | WAP | Web Services | XML


 
  
 
Programming Tutorials: Ajax | Articles | JSP | Bioinformatics | Database | Free Books | Hibernate | J2EE | J2ME | Java | JavaScript | JDBC | JMS | Linux | MS Technology | PHP | RMI | Web-Services | Servlets | Struts | UML
 

 
Facing Programming Problem?
Ask Questions?, Browse Latest Questions, Question-Answer Guidelines
Java
  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification
  Java Applet
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 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 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

 

                         

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 

Current Comments

1 comments so far (
post your own) View All Comments Latest 10 Comments:

I read your example code here. Thanks for this.

What if we have duplicate values in the property file, e.g.

name = rahul
name = jeet
age = 10
code = 30

here the name is duplicate, if i use your sample code I only can get the following:

name = jeet
age = 10
code = 30

Which does not give all the property values. Could you please suggest a way so i can retrieve the duplicate fields from the property file as well. My property file contain lots of duplicate elements and i want to read all.

Thanks in advance for your help.

BR,
Rahul

Posted by Rahul on Tuesday, 08.5.08 @ 13:05pm | #71066

Latest Searches:
excel from java
extract a piece of dat
joining queries in SQ
JPA
java �����??
struts <param name
myfaces tomahawk
convert string array t
notes on javax.sql.*
array list
diff. shape of linear
image file upload jsp
table model
c tutorial
Photoshop Photo Effect
loading bars images in
org.apache.poi.hssf.us
jdk1.4
<html:options>
jsp onchange
rs.relative
upsasting
project
Flash Simple Motion Tw
how to pass same varia
struts hibernate sprin
Scanner
compiler design
jdk1.3vsjdk1.4
seperator
Treemap using gwt tree
Easy Java Tutorials
java tutorial pdf
video tutorial
datalist
login
upload file
FORMAT YEARS
JSF datatree
is the jvm same for al
t:datalist
Dependency list box in
ensureCapacity of vect
Photoshop Text Reflect
Java GUI example
Component class in JSF
java applets
sum of digits
struts radio button
Determining If a Year
jsp standard tags
Jtable Jbutton
how to create a frame
jpanel
awt jdbc
asterisk
if statement in a JSP
? С??? С??? С???
table grid
sample code using stru
MurachÑ??Ð?Ñ?Ð?Ð??Ñ??Ð
jpa spring transaction
convert ASCII to char
struts formfile
rules
HWPF
Message Board JMB
Write a program that i
java inner class
connect SQL server in
javax.sql.* package of
Hibernate Set Attribut
data grid
program in java to ins
Read Cookies from Serv
getter setter methods
js tag
vector in java
Mylyn
Photoshop Text Effects
Java String toLowerCase Example
Java String toCharArray Example
Java String substring Example
Java String indexOf Example
Java String startsWith Example
Java String hashCode Example
Java String matches Example
Java String length Example
Java String lastIndexOf Example
Java String isEmpty Example
Java String equalsIgnoreCase Example
Java String equals Example
Java String endsWith Example
Java String copyValueOf Example
Java String contentEquals Example
  EAI Articles
  Java Certification
Tell A Friend
Your Friend Name
Search Tutorials

 

 
 
Browse all Java Tutorials
Java JSP Struts Servlets Hibernate XML
Ajax JDBC EJB MySQL JavaScript JSF
Maven2 Tutorial JEE5 Tutorial Java Threading Tutorial Photoshop Tutorials Linux Technology
Technology Revolutions Eclipse Spring Tutorial Bioinformatics Tutorials Tools SQL
 

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 | 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.