Source Code : Load properties from XML file
Java Is Open Source Programming Language You Can Download From Java and Java Libraries From http://www.oracle.com.
Click Here to download
We provide this code related to title for you to solve your developing problem easily. Libraries which is import in this program you can download from http://www.oracle.com.
Click Here or search from google with Libraries Name you get jar file related it
Load properties from XML file
/*
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
<properties>
<comment>Application Configuration</comment>
<entry key="data.folder">D:Data</entry>
<entry key="jdbc.url">jdbc:mysql://localhost/mydb</entry>
</properties>
*/
import java.io.FileInputStream;
import java.util.Properties;
public class Main {
public static void main(String[] args) {
Properties properties = new Properties();
String dataFolder = properties.getProperty("data.folder");
System.out.println("dataFolder = " + dataFolder);
String jdbcUrl = properties.getProperty("jdbc.url");
System.out.println("jdbcUrl = " + jdbcUrl);
}
public Properties readProperties() throws Exception {
Properties properties = new Properties();
FileInputStream fis = new FileInputStream("configuration.xml");
properties.loadFromXML(fis);
return properties;
}
}
Thank with us