加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-16 02:21:58 所属栏目:百科 来源:网络整理
导读: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" prop

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:secondsrcmainresourcessecrets.properties");
//InputStream input4 = new FileInputStream("/main/resources/properties.xml");
;

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读