Sunday, April 29, 2018

Write data from properties to xml file !!

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

  4. public class WritePropertiesXmlFile {
  5. public static void main(String[] args) throws Exception {
  6. Properties properties = new Properties();
  7. properties.setProperty("suresh", "2000");
  8. properties.setProperty("mahesh", "1200");
  9. properties.setProperty("ritesh", "2100");

  10. File file = new File("D:\\test2.xml");
  11. FileOutputStream fileOut = new FileOutputStream(file);
  12. properties.storeToXML(fileOut, "balance-sheet");
  13. fileOut.close();
  14. }
  15. }
Output:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
<properties>
<comment>balance-sheet</comment>
<entry key="ritesh">2100</entry>
<entry key="suresh">2000</entry>
<entry key="ishaan">0000</entry>
<entry key="mahesh">1200</entry>
</properties>

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