Pages

Friday, July 3, 2015

How to get value from properties file

To get information from the properties file, create the properties file first.

db.properties
  1. user=system  
  2. password=oracle  
Test.java

  1. import java.util.*;  
  2. import java.io.*;  
  3. public class Test {  
  4. public static void main(String[] args)throws Exception{  
  5.     FileReader reader=new FileReader("db.properties");  
  6.       
  7.     Properties p=new Properties();  
  8.     p.load(reader);  
  9.       
  10.     System.out.println(p.getProperty("user"));  
  11.     System.out.println(p.getProperty("password"));  
  12. }  
  13. }  

No comments:

Post a Comment