There are many ways to read properties file in java. Here explained, using
1. ResourceBundle
2. Properties Class
How to use this
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
----
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());
}
}
AlgoMonster Annual Plan 60% OFF - Is it really worth it for Coding
Interview Preparation?
-
Hello guys, the holiday season is the perfect time to invest in yourself.
And if you’re preparing for coding interviews at FAANG or top-tier tech
compani...
2 hours ago
No comments:
Post a Comment
I'm certainly not an expert, but I'll try my hardest to explain what I do know and research what I don't know.