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);
}
}
查看全文
相关阅读:
解决Eclipse点击运行后控制台不能自动弹出的问题
vc中的空格怎么变成了“ `”或“^”,怎么变回来
ping百度域名时的收获
java学习(权限修饰符)
can't create socket (must run as root?) : Permission denied
Zabbix各种报错信息和遇到的问题
windows2012r2 更改管理员密码
Zabbix钉钉机器人报警
用route命令添加永久路由
zabbix使用jmx监控tomcat
原文地址:https://www.cnblogs.com/yangy608/p/2726508.html
最新文章
ASP.NET简介
Sql Server 分页
软件名居中显示
sql server 去掉某字段左边的0
groovy程序设计
Promise
RxJS
摩尔投票法
angular的路由
angular使用@angular/material 出现"export 'ɵɵinject' was not found in '@angular/core'
热门文章
js中的BOM和DOM常用事件方法
angular项目中ts的配置编译tsconfig.json
angular装饰器
new angular 项目的工作区配置文件和应用源文件
sqlserver日期函数大全
数据结构:单链表的就地逆置
完成代码将x插入到该顺序有序线性表中,要求该线性表依然有序
如何通过编程解决华容道问题?
java基础编程练习
Eclipse常用快捷键
Copyright © 2011-2022 走看看