zoukankan
html css js c++ java
读取src下的属性文件的某个key值
读取src下的属性文件的某个key值
/**
* 读取src下某个属性文件中的某个key所对应的value
*
* @param args
*
*/
public static void main(String[] args) {
String key = "file.upload.folder";
String propertiesFileFullName = "myProperty.properties";
String pbundle = "myProperty";
fun1(propertiesFileFullName, key);
fun2(propertiesFileFullName, key);
fun3(pbundle, key);
}
// 方法一
public static void fun1(String propertiesFileFullName, String key) {
Properties pop = new Properties();
InputStream fs = null;
try {
fs = ReadOneValue.class.getClassLoader().getResourceAsStream(
propertiesFileFullName);
pop.load(fs);
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
fs.close();
} catch (IOException e) {
e.printStackTrace();
}
}
String value = pop.getProperty(key);
System.out.println("属性文件的上传路径为:" + value);
}
// 方法二
public static void fun2(String propertiesFileFullName, String key) {
Properties pop = new Properties();
String classpath = Thread.currentThread().getContextClassLoader()
.getResource("").getPath();
FileInputStream fs = null;
try {
fs = new FileInputStream(classpath + "/" + propertiesFileFullName);
pop.load(fs);
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
fs.close();
} catch (IOException e) {
e.printStackTrace();
}
}
String value = pop.getProperty(key);
System.out.println("读取到的值为:" + value);
}
// 方法三
public static void fun3(String filename, String key) {
Locale locale = Locale.getDefault();
ResourceBundle localResource = ResourceBundle.getBundle(filename,
locale);
String value = localResource.getString(key);
System.out.println("读取到的值为:" + value);
}
}
查看全文
相关阅读:
Python 命令模式和交互模式
Python自带IDE设置字体
Python2.7和3.7区别
Kubernetes1.91(K8s)安装部署过程(八)-- kubernetes-dashboard安装
Kubernetes1.91(K8s)安装部署过程(七)--coredns安装
nginx 设置自签名证书以及设置网址http强制转https访问
Kubernetes1.91(K8s)安装部署过程(六)--node节点部署
VMware安装VMware tool是 遇到The path "" is not a valid path to the 3.10.0-693.el7.x86_64 kernel headers.
第三方git pull免密码更新
Kubernetes1.91(K8s)安装部署过程(五)--安装flannel网络插件
原文地址:https://www.cnblogs.com/yangy608/p/2726508.html
最新文章
ORA-00257
exp/imp三种模式——完全、用户、表
EL表达式 介绍
Eclipse内存错误java heap space
ora-12170 与 Oracle lsnrctl
一文带你了解单例模式
一文看懂观察者模式及案例分析
使用Redis实现中英文自动补全功能详解
开发dubbo应用程序(二)dubbo注册中心相关概述
开发dubbo应用程序(一)入门demo详解
热门文章
mybatis插入数据后返回自增主键ID详解
SpringBoot与PageHelper的整合示例详解
MyBatis-Plus入门Demo详解
python 各种开源库
Python3.7和数据库MySQL 8.0.12 数据库数据驱动mysql-connector安装(四)
Python3.7和数据库MySQL 8.0.12 数据库SQLite3连接(三)
Python3.7和数据库MySQL 8.0.12 绿色解压 安装教程(一)
Python3.7和数据库MySQL交互(二)SQLyog安装教程
PyCharm安装使用 激活码
Python变量类型
Copyright © 2011-2022 走看看