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);
}
}
查看全文
相关阅读:
Pandas to_sql将DataFrame保存的数据库中
Pandas 的groupby操作
Hibernate(一)
EasyUI
Java面试题
Solr
Lucene
SpringMVC(二)
MyBatis(二)
MyBatis(一)
原文地址:https://www.cnblogs.com/yangy608/p/2726508.html
最新文章
Java学习笔记之——Set容器
Java学习笔记之——TreeMap
Java学习笔记之——LinkedList
基于golang官方mongo-driver操作总结
PHP编译安装报错:configure: error: mcrypt.h not found. Please reinstall libmcrypt
celery使用rabbitmq报错[Errno 104] Connection reset by peer.
centos7
php7编译安装-php-fpm.service
Centos7-跟踪用户操作记录并录入日志
php7-编译安装参数
热门文章
mariadb-my.cnf
pymysql操作mysql的脚本示例
英语国际音标表格
Bash学习要点
pandas时序处理相关功能
滑动平均模型在Tensorflow中的应用
sklearn 基本的文本分类
Pnadas 通过SQL处理数据并读取结果到DF
Pandas 连续差分diff后恢复原始的序列
Pandas读取Mysql中的表
Copyright © 2011-2022 走看看