Java properties all keys

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.

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.

Get All Keys and Values of the Properties files in Java

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 ()) ;
>
>
>

Tutorials

  1. Java util package Examples
  2. Java Util Package — Utility Package of Java
  3. Generating Random Number
  4. Breaking the String into Words
  5. Listing all available Locales
  6. Setting the default Locale
  7. Associate a value with an object
  8. Comparing Arrays
  9. Shuffling the Element of a List or Array
  10. Collections Framework
  11. Collection Iterate Example
  12. Converting Collection to an Array
  13. Converting an Array to a Collection
  14. Implement the Queue in Java
  15. Implementing a Stack in Java
  16. Implementing a Least-Recently-Used(LRU) Cache
  17. Creating a Copy of a Collection
  18. Making a Collection Read-Only
  19. Sorting elements of a Collection
  20. Creating a Hash Table
  21. Finding an Element in a Sorted Array
  22. Read the Key-Value of Property File in Java
  23. Get All Keys and Values of the Properties files in Java
  24. Write the Keys and Values of the Properties files in Java
  25. Scheduling a Timer Task
  26. Getting the Current Time
  27. Getting Information of All Available Time Zones
  28. Getting the current date
  29. Determining the Number of Days in a Month
  30. Comparing Dates in Java
  31. Determining the actual age from date of birth in Java
  32. Determining If a Year is a Leap Year in Java
  33. Determining the Day-of-Week for a Particular Date
  34. What is a JAR file in Java
  35. Creating a JAR file in Java
  36. Viewing contents of a JAR File
  37. Listing the Main Attributes in a JAR File Manifest
  38. Creating a ZIP file in Java
  39. Listing Contents of a ZIP File
  40. Unzip a ZIP File

Источник

Читайте также:  Python threading возврат значения
Оцените статью