读取.properties文件
【读取.properties文件】环境:eclipse
步骤一:
创建Maven项目
步骤二:
创建PropertiesUtil类:
package Tool;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
public class PropertiesUtil{//输出name属性文件内容
public static void outputvalusofProperty(String name) throws IOException{
InputStream in=ClassLoader.getSystemResourceAsStream(name);
Properties pro =new Properties();
pro.load(in);
for (String key:pro.stringPropertyNames()){
System.out.println("key:"+key+" "+"value:"+pro.getProperty(key));
}
}//获取filename属性文件中,关键字为key的值
public static String getProperty(String filename,String key) throws IOException{
InputStream in=ClassLoader.getSystemResourceAsStream(filename);
Properties pro =new Properties();
pro.load(in);
if(pro.containsKey(key))
return pro.getProperty(key);
else
return null;
}
}
推荐阅读
- Arduino+ESP32专题|【软件使用】新增了文件,但更新到Tortoise SVN里却没有增加
- #|Mybatis学习 && 配置解析
- Typora+picgo+github图片及文件上传
- SpringBoot集成SFTP客户端实现文件上传下载实例
- Quartus 使用 tcl 文件快速配置管脚
- 使用Node.js打包下载文件
- springboot|springboot两种配置文件bootstrap.properties和application.properties的区别
- FastDFS蛋疼的集群和负载均衡(十一)之清除Nginx文件缓存
- 新建项目库文件目录列表
- Linux 系统下 查找文件 命令总结,这个很哇塞!