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);
}
}
查看全文
相关阅读:
C++高精度运算类bign (重载操作符)
Spring4.0支持Groovy配置
统计Oracle数据库文件的大小
ThinkPHP pdo连接Oracle的配置写法,提示报错
【PHP缩略图类】手机照片不能生成缩略图问题以及解决方式
ping and traceroute(tracert)
HDU-1053-Entropy(Huffman编码)
Python学习之四【变量】
linux mysql
xorm
原文地址:https://www.cnblogs.com/yangy608/p/2726508.html
最新文章
小米畅聊也将瞄准镜对向微信电话本
易信推专线电话 通话双方中只需一方安装即可免费通话
微信或成为央视春晚互动工具
QQ公众号?是的,你没看错!
后悔药来了?发出去的微信图文消息删除后不再显示
卡券核销助手微信公众服务号全面升级 并更名为“卡券商户助手”
公众平台自动回复支持插入微信卡券 多图文消息可嵌入卡券
微信公众平台"微信连Wi-Fi"功能来了 线下微信增粉利器
公众平台开发者中心接口权限列表改版 细分接口类别方便查阅见监控
微信公众号支付测试功能策略调整 加快商户申请速度
热门文章
"微信全球商业创新大赛-创意中国2015"国际MBA商业挑战赛开启
张小龙:学习和快速迭代比过去的经验更重要 一切从用户角度出发
听同事讲 Bayesian statistics: Part 2
Kaggle Competition Past Solutions
Investigation of Different Nets and Layers
matlab中 hold on 与hold off的用法
【原创】Matlab中plot函数全功能解析
IEEE会议排名(转载)
两阶段提交协议的异常处理
蚂蚁爬杆之动态演示
Copyright © 2011-2022 走看看