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

Blueprint for self-improvement

To learn faster: Make the process fun To understand yourself : Write To understand the world better : Read To build deeper connection : Lis...