How to read properties file using java

Please support our Java advertiser: Programming Forums - DaniWeb Sister Site
Reply

Join Date: May 2009
Posts: 7
Reputation: BinodSuman is an unknown quantity at this point 
Solved Threads: 0
BinodSuman BinodSuman is offline Offline
Newbie Poster

How to read properties file using java

 
0
  #1
Jun 1st, 2009
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
  1. import java.io.FileInputStream;
  2. import java.io.IOException;
  3. import java.util.Enumeration;
  4. import java.util.Properties;
  5. import java.util.ResourceBundle;
  6.  
  7.  
  8. public class ReadPropFile {
  9.  
  10. public static void main(String[] args) {
  11. // readpropFile();
  12. otherway();
  13. }
  14.  
  15. public static void readpropFile(){
  16. ResourceBundle bundle = ResourceBundle.getBundle("MyProp");
  17. String studentName = bundle.getString("name");
  18. String roll = bundle.getString("roll");
  19. System.out.println("Student Name :: "+studentName);
  20. System.out.println("Roll Number :: "+roll);
  21.  
  22. // Fetch all the Properties.
  23.  
  24. Enumeration keys = bundle.getKeys();
  25. while(keys.hasMoreElements()){
  26. System.out.println(keys.nextElement());
  27. }
  28.  
  29. }

SNIP

Thanks,

Binod Suman
Last edited by happygeek; Jun 5th, 2009 at 8:17 am. Reason: Code Tags / Plug snipped
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 979
Reputation: JamesCherrill is just really nice JamesCherrill is just really nice JamesCherrill is just really nice JamesCherrill is just really nice JamesCherrill is just really nice 
Solved Threads: 145
JamesCherrill JamesCherrill is online now Online
Posting Shark

Re: How to read properties file using java

 
0
  #2
Jun 1st, 2009
... yes, but what is your question?
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC