In this example we will show about how to convert XML file into properties file.
Source Code
(1)Test.xml
Support Email
Alice
(2)ConvertXMLfile.java
package com.beginner.examples;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.InvalidPropertiesFormatException;
import java.util.Properties;
public class ConvertXMLfile {
public static void main(String[] args) {
Properties properties = new Properties();
try {
InputStream inputStream = new FileInputStream("E:tmpTest.xml");
properties.loadFromXML(inputStream);
String email = properties.getProperty("name");
System.out.println(email);
} catch (FileNotFoundException e) {
e.printStackTrace();
}catch(InvalidPropertiesFormatException e) {
e.printStackTrace();
}catch(IOException e) {
e.printStackTrace();
}
}
}
Output:
Alice
References
Imported packages in Java documentation: