Java program for properties file to XML conversion

Properties file to XML conversion is easy.

Below program helps you to do it.

Load the property file or set sample properties using setProperty in the below code and run.

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Properties;

public class PropertiesXML
{
    public static void main(String[] args) throws IOException
    {
        Properties props = new Properties();
        FileInputStream fin = new FileInputStream("e:/test.properties");
        props.load(fin);
        props.setProperty("sampleKey", "sampleVlue");
        OutputStream os = new FileOutputStream("e:/test.xml");
        props.storeToXML(os, "Description","UTF-8");
        System.out.println("Done");
    }
}

Note: Double click anywhere within the code to select the full code snippet.

Leave a Reply

Your email address will not be published. Required fields are marked *