import java.io.FileOutputStream; import java.util.Properties; public class Example { public static void main(String[] args) throws Exception { Properties props = new Properties(); props.setProperty("name", "John Smith"); props.setProperty("email", "[email protected]"); FileOutputStream fos = new FileOutputStream("config.xml"); props.storeToXML(fos, "Application Configuration"); } }
import java.io.FileOutputStream; import java.util.Properties; public class Example { public static void main(String[] args) throws Exception { Properties props = new Properties(); props.setProperty("username", "admin"); props.setProperty("password", "secret"); props.setProperty("server", "localhost"); FileOutputStream fos = new FileOutputStream("config.xml"); props.storeToXML(fos, "Database Configuration", "UTF-8"); } }This code creates a Properties object, adds three key-value pairs, and writes them to an XML file called "config.xml". The third parameter of the storeToXML method specifies the encoding of the XML file. The storeToXML method is part of the java.util package library.