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);
}
}
查看全文
相关阅读:
UIWebView 设置字体样式和行间距
UIAlertView问题
仿jquery的函数
css 不换行,换行
兼容火狐插入背景音乐
防止屏蔽window.onload函数
mysql
解决手机浏览器上input 输入框导致页面放大的问题
vue 中监听页面滚动
WCF处理异常的方式
原文地址:https://www.cnblogs.com/yangy608/p/2726508.html
最新文章
202120221课程设计第一周进展
202120221课程设计第二周进展
程序运行
戒烟第二天!
Sage Accpac ERP 销售订单模块激活问题!
datalist嵌套TreeView
Asp.net 团队博客地址
戒烟第一天!
扩展fckeditor的上传图片和上传文件功能! (二)
SQL2000游标引发的性能问题!
热门文章
翟鸿燊《国学应用大智慧》笔记
戒烟第五天!
收发邮件的一些心得。
监控UITextView和UITextField的键盘确定事件以及字数控制
UIImage imageNamed:误区
CoreData
No architectures to compile for (ONLY_ACTIVE_ARCH=YES, active 
iOS下载文件,保存路径. 防止加到iCloud备份
iOS存储数据到相应目录的问题
switch case in protected scope 异常解决
Copyright © 2011-2022 走看看