import java.io.FileOutputStream;
import java.util.Properties;
public class Xmltest {
public static void main(String[] args) {
try {
String filePath = System.getProperty("user.dir")+"\\src\\write2XML.xml";
File file = new File(filePath);
FileOutputStream fos = new FileOutputStream( file );
Properties prop = new Properties();
prop.setProperty("NumberOne", "One");
prop.setProperty("NumberTwo", "Two");
prop.setProperty("NumberThree", "Three");
prop.storeToXML(fos, "This is header comment");
}
catch (Exception e ) {
e.printStackTrace();
}
}
}
Output:
Output xml file "write2XML.xml" will be created with below contents:
No comments:
Post a Comment