首页 > 其他 > 详细

怎么读取properties文件和ini文件?

时间:2019-10-29 17:25:19      阅读:118      评论:0      收藏:0      [点我收藏+]

一、读取properties文件:

properties中的内容:

server.ip = 127.0.0.1
server.port = 22

 

//原生java即可读取
public
static void setting() throws FileNotFoundException, IOException{ File configFile = new File("conf/parameters.properties"); FileInputStream fis = new FileInputStream(new File(configFile .getAbsoluteFile().getCanonicalPath())); Properties props = new Properties(); props.load(fis); String serverIp = (String) props.get("server.ip"); InetAddress inetAddress = InetAddress.getByName(serverIp); Integer serverPort = Integer.valueOf((String) props.get("server.port")); }

 

二、读取ini文件:

ini文件中的内容:

[server]
ip=127.0.0.1
port=22

 

需要引入ini4j的jar包,包下载地址:https://repo1.maven.org/maven2/org/ini4j/ini4j/0.5.4/ini4j-0.5.4.jar

Wini ini = new Wini(new File("conf/monitor.ini"));
       String serverIp = ini.get("server","ip");
       InetAddress inetAddress = InetAddress.getByName(serverIp);
       Integer serverPort = Integer.valueOf(ini.get("server","port"));

 

怎么读取properties文件和ini文件?

原文:https://www.cnblogs.com/blackjoyful/p/11759222.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!