package demo.xml;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Properties;
public class PropXmlDemo {
public static void main(String[] args) throws IOException {
propsToXml();
xmlToProps();
}
static void propsToXml() throws IOException{
Properties props = new Properties();
//overwrite by the next my.email
props.setProperty("my.email", "aaa.mail@163.com");
props.setProperty("my.email.1", "aaa.mail@163.com");
props.setProperty("my.email", "111aaa.mail@163.com");
OutputStream out = new FileOutputStream("c:\\a.xml");
props.storeToXML(out, "my.comments");
out.close();
}
static void xmlToProps()throws IOException{
Properties props = new Properties();
//PropXmlDemo.class.getClassLoader().getResourceAsStream("a.xml");
InputStream is = new FileInputStream("c:\\a.xml");
props.loadFromXML(is);
is.close();
System.out.println(props.getProperty("my.email"));
System.out.println(props.getProperty("my.email.1"));
}
}
[Java]XML与Properties
最新推荐文章于 2024-07-21 22:27:18 发布