Sunday, April 29, 2018

Write the data in properties file !!

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

  5. public class WritePropertiesFiles {

  6. public static void main(String[] args) throws IOException {
  7. Properties prop = new Properties();
  8. prop.setProperty("bangalore", "raju");
  9. prop.setProperty("delhi", "ritesh");
  10. prop.setProperty("chennai", "ishaan");
  11. prop.setProperty("japan", "chet");

  12. File file = new File("D:\\contacts.properties");
  13. FileOutputStream fileStream = new FileOutputStream(file);
  14. prop.store(fileStream, "store the contacts");
  15. fileStream.close();
  16. }
  17. }
Output:
#store the contacts
#Sun Apr 29 20:22:15 IST 2018
delhi=ritesh
japan=chet
chennai=ishaan
bangalore=raju

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...