java读取配置文件jar包_java 获取jar包内外的配置文件

程序运行,

有时候需要获取jar包内内容, 例如版本更新信息,新增文本提示等

有时候需要获取jar包外内容, 例如每个系统运行的环境, 系统名称等

当前用的是spring clud框架

获取到jar包内配置文件

String fileName = "文件名.xml";

InputStream is = this.getClass().getResourceAsStream("/"+fileName); //通过java getclass 获取到jar包内文件, 获取到输入流

private static Map verMap = new HashMap<>();

if (document == null)

return;

List> tables = document.selectNodes("UrlList"); //通过document 的方法, 解析xml

if (tables != null && tables.size() > 0) {

for (Object obj : tables) {

Element urlList = (Element) obj;

for (Object urlObj : urlList.selectNodes("url")) {

Element urlElement = (Element) urlObj;

String verid = urlElement.attributeValue("verid");

String vernum = urlElement.attributeValue("vernum");

String vertime = urlElement.attributeValue("vertime");

String vertext = urlElement.getText();

if (!verMap.containsKey(verid)){

ObjectNode objectNode = Convert.newObject();

objectNode.put("verid", verid);

objectNode.put("vernum", vernum);

objectNode.put("vertime", vertime);

objectNode.put("vertext", vertext);

verMap.put(verid, objectNode);

}

}

}

}

2、

1、

通过ConfigUtil.getApplicationPath()获取到项目运行绝对地市

File.separator 斜线, 文件夹符号

String configPath = "file:"+ConfigUtil.getApplicationPath()+File.separator+"conf"+File.separator+"applicationContext.xml";

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值