Using Properties class:
<?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>
- import java.io.File;
- import java.io.FileOutputStream;
- import java.util.Properties;
- public class WritePropertiesXmlFile {
- public static void main(String[] args) throws Exception {
- Properties properties = new Properties();
- properties.setProperty("suresh", "2000");
- properties.setProperty("mahesh", "1200");
- properties.setProperty("ritesh", "2100");
- File file = new File("D:\\test2.xml");
- FileOutputStream fileOut = new FileOutputStream(file);
- properties.storeToXML(fileOut, "balance-sheet");
- fileOut.close();
- }
- }
<?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