怎么读取properties文件和ini文件?
2024-08-27 17:00:23
一、读取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"));
最新文章
- 快速Android开发系列网络篇之Volley
- laravel框架中容器类简化代码-摘自某书
- 背水一战 Windows 10 (30) - 控件(文本类): AutoSuggestBox
- 47个过程(PMBOK2008)
- IIS的配置
- September 9th 2016 Week 37th Friday
- ibatis动态查询条件
- <;转>;thinkphp的各种内部函数 D()、F()、S()、C()、L()、A()、I()详解
- 【Redis】配置redis主从复制
- 关于Java(标识符规则)
- 2014第35周三jquery最近用到的内容总结
- IOS_多线程_ASI_AFN_UIWebView
- 学习笔记TF009:对数几率回归
- 练习html,css,js仿制百度首页
- Axure RP 7 8
- python之路(五)-文件操作
- spark、standalone集群 (2)集群zookeeper 热备
- HDU6031 Innumerable Ancestors 倍增 - 题意详细概括 - 算法详解
- 【Oracle】【8】大批量update某个字段
- Windows 下vim的配置文件_vimrc
热门文章
- 【用户体验度量】用户费力度评分(CES)
- (十)java虚拟机性能监控工具
- Nginx作为负载均衡把客户端真实IP发送给后端配置
- Spring Aop(十六)——编程式的自定义Advisor
- CEIWEI USBMonitor监控驱动 OCX/SDK USB 监控精灵 USB过滤驱动
- Egret入门学习日记 --- 第三篇 (书中 3.4 内容)
- COLLATION &#39;latin1_swedish_ci&#39; is not valid for CHARACTER SET &#39;utf8&#39;
- Linux程序Segmentation fault (core dumped)
- [翻译向] 当flush privileges生效时
- oracle学习笔记day1