jive 2.5 中读取xml配置文件 之 Properties基础篇
package src;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;
public class PropTest {
public static void main(String[] args) throws FileNotFoundException, IOException {
Properties prop=new Properties();
prop.load(new FileInputStream("config.properties"));
System.out.println(prop.get("mykey"));
System.out.println("------XML------");
prop.loadFromXML(new FileInputStream("config.xml"));
System.out.println(prop.get("password"));
//可以利用outPutStream来输出,也就是一定程度上实现管理功能
}
}
config.properties
mykey = chen
myvalue = chen-value
config.xml
<?xml version="1.0" encoding="UTF-8"?>
<!-- 注意加载properties.dtd 标签库-->
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
<properties>
<entry key="password">password</entry>
<entry key="user">chen</entry>
</properties>