| | |
How to read properties file using java
Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
![]() |
•
•
Join Date: May 2009
Posts: 7
Reputation:
Solved Threads: 0
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
SNIP
Thanks,
Binod Suman
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()); } }
SNIP
Thanks,
Binod Suman
Last edited by happygeek; Jun 5th, 2009 at 8:17 am. Reason: Code Tags / Plug snipped
![]() |
Similar Threads
- How to read the first record in a file in java and delete it (Java)
- Read properties file (Java)
- Help to read .pst file from java (Java)
- how to read CSV file in java (Java)
Other Threads in the Java Forum
- Previous Thread: Jar File Images
- Next Thread: Layer painting with JLayeredPane
| Thread Tools | Search this Thread |
-xlint android api applet application array arrays automation bi binary blackberry block bluetooth chat class classes client code compile compiler component database developmenthelp draw eclipse error event exception fractal freeze game gameprogramming givemetehcodez graphics gui html ide image input integer j2me j2seprojects java javac javaprojects jetbrains jni jpanel jtable julia learningresources lego linux list login loop loops mac map method methods mobile netbeans newbie notdisplaying number online oracle page print problem program programming project qt recursion scanner screen server set singleton size sms sort sql string swing system template textfields threads time title tree tutorial-sample update variablebinding windows working xor





