Monday, April 30, 2018

Read the data from properties file !!

Using Properties class:
  1. import java.io.File;
  2. import java.io.FileInputStream;
  3. import java.io.IOException;
  4. import java.util.Enumeration;
  5. import java.util.Properties;

  6. public class ReadPropertiesFiles {
  7. public static void main(String[] args) throws IOException {

  8. File file = new File("D:\\contacts.properties");
  9. FileInputStream fis = new FileInputStream(file);
  10. Properties prop = new Properties();
  11. prop.load(fis);
  12. fis.close();

  13. Enumeration enuKeys = prop.keys();
  14. while (enuKeys.hasMoreElements()) {
  15. String key = (String) enuKeys.nextElement();
  16. String value = prop.getProperty(key);
  17. System.out.println(key + " = " + value);
  18. }
  19. }
  20. }
Output:
delhi = sumit
japan = chet
bangalore = raju
chennai = ishaan

No comments:

Post a Comment

How to run standalone mock server on local laptop

 Please download the standalone wiremock server from Direct download section at the bottom of the page.  Download and installation Feel fre...