Read Properties file in Java


package com.test;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Enumeration;
import java.util.Locale;
import java.util.Properties;
import java.util.ResourceBundle;
public class ReadPropetiesFile {
public static void main(String a[]){
String fileName = "test.properties";
ReadPropetiesFile readProp = new ReadPropetiesFile();
readProp.readProperties(fileName);
}
public void readProperties(String fileName){
try {
ResourceBundle labels = ResourceBundle.getBundle(fileName, Locale.ENGLISH);
Enumeration bundleKeys = labels.getKeys();
while (bundleKeys.hasMoreElements()) {
    String key = (String)bundleKeys.nextElement();
    String value = labels.getString(key);
    System.out.println("key = " + key + ", " +   "value = " + value);
}
}catch (Exception e) {
e.printStackTrace();
}
}
}

One thought on “Read Properties file in Java

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.