【Practical】Eclipse项目中创建.properties属性文件及其中属性

找到项目的目录下的src文件夹

创建xxx.txt文件

在txt文件中输入配置的资源

在这里插入图片描述

将其改名为xxx.properties

Eclipse项目中读取该属性文件以及其中属性的方法

//Get .properties
Property = new Properties();
Property.load(Thread.currentThread()
					.getContextClassLoader()
					.getResourceAsStream("xxx.properties"));
//Get property				
String IP_addr = Property.getProperty("IP");
int PortNum = Integer.parseInt(Property.getProperty("Port"));

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_44246009/article/details/107425194