属性文件读取以及写属性文件到XML文档

package com.gxnu.edu.lqm.collection.test;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Properties;

import org.junit.Test;

public class PropertyTest {
@Test
public void testProperties(){
Properties pro = new Properties();
try(
InputStream is = Files.newInputStream(Paths.get("E:","b.properties"));
){
pro.load(is);
}catch(Exception e){
e.printStackTrace();
}
String sName = pro.getProperty("name");
String sHeight = pro.getProperty("height");
System.out.println(sName+"\t"+sHeight);
try {
pro.storeToXML(new FileOutputStream("e:/a.xml"), "aaaa");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
};

}

}

猜你喜欢

转载自www.cnblogs.com/jiminluo/p/jimin.html