How to read properties file using Java?


There are many ways to read properties file in java. Here explained two wayS, using

1. ResourceBundle
2. Properties Class

How to use this tutorial
1. Create one directory src and put both below files (MyProp.properties and ReadPropFile.java)

2. MyProp.properties
name = Binod Kumar Suman
roll = 110
city = Bangalore

3. ReadPropFile.java
java Syntax (Toggle Plain Text
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Enumeration;
import java.util.Properties;
import java.util.ResourceBundle;


public class ReadPropFile {

public static void main(String[] args) {
// readpropFile();
otherway();
}

public static void readpropFile(){
ResourceBundle bundle = ResourceBundle.getBundle("MyProp");
String studentName = bundle.getString("name");
String roll = bundle.getString("roll");
System.out.println("Student Name :: "+studentName);
System.out.println("Roll Number :: "+roll);

// Fetch all the Properties.

Enumeration keys = bundle.getKeys();
while(keys.hasMoreElements()){
System.out.println(keys.nextElement());
}

}

People who read this post also read :



1 comments:

Amazing Article, thank you!. I am very glad to read your informative & practical blog. Kindly keep updating your blog.
Java Developer is a wonderful career for IT students.To start Dream Career to become a Java developer learn from
Java Training in Chennai
. or learn thru Java Online Training from India .

Post a Comment

Share

Twitter Delicious Facebook Digg Stumbleupon Favorites More