读取properties文件,以及properties文件转成xml文件

secrets.properties文件,里面是类似于key-value形式的数据

test=1d9ae43c7f0efa1261174ba82840bb0f

转换成对应的xml文件:properties.xml

<?xml version="1.0" encoding="UTF-8"?>  
<!DOCTYPE properties SYstem "http://java.sun.com/dtd/properties.dtd">  
<properties>   
    <entry  key="test"><![CDATA[1d9ae43c7f0efa1261174ba82840bb0f]]></entry>  
</properties>

java读取

InputStream input1 = BasicAuthUtil.class.getClassLoader().getResourceAsstream("secrets.properties");
//InputStream input2 = BasicAuthUtil.class.getResourceAsstream("/ipConfig.properties")
//InputStream input3 = new FileInputStream("D:\\second\\src\\main\\resources\\secrets.properties");
//InputStream input4 = new FileInputStream("/main/resources/properties.xml");
;

上面的前两种方式都是通过反射方式来获取文件的,第一种是不需要考虑路径的问题,第二种是需要加上“/”;后面第三种是根据绝对路径来读取;第四种是读取的xml文件

相关文章

php输出xml格式字符串
J2ME Mobile 3D入门教程系列文章之一
XML轻松学习手册
XML入门的常见问题(一)
XML入门的常见问题(三)
XML轻松学习手册(2)XML概念