How to parse project properties or how to parse files with key-value pair
If a file has content like
app.enabled = false
app.host = "localhost"
app.port = 8080
app.zoneId = "zone_id"
app.fulOpId = "test_uk_1"
which are all key-value pairs, we could use properties.load() to parse it.
public static Properties loadProperties() {
Properties properties = new Properties();
try {
InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream("project.properties");
if(in==null) {
logger.warn("The project.properties file does not exist");
} else {
properties.load(in);
}
} catch(Exception e) {
logger.error("Unable to read the project.properties", e);
}
return properties;
}
The reason to use Thread.currentThread().getContextClassLoader().getResourceAsStream("project.properties") and why it is different from normal class loader:
Each class will use its own classloader to load other classes. So if ClassA.class references ClassB.class then ClassB needs to be on the classpath of the classloader of ClassA, or its parents. The thread context classloader is the current classloader for the current thread. An object can be created from a class in ClassLoaderC and then passed to a thread owned by ClassLoaderD. In this case the object needs to use Thread.currentThread().getContextClassLoader() directly if it wants to load resources that are not available on its own classloader.
How to parse project properties or how to parse files with key-value pair的更多相关文章
- Android requires compiler compliance level 5.0 or 6.0. Found '1.8' instead. Please use Android Tools>Fix project Properties.
重装操作系统之后,或者破坏了Android的开发环境之后,需要重新配置好Android的开发环境.但是配置好后,导入原有的项目时,报错: Android requires compiler compl ...
- Type Project has no default.properties file! Edit the project properties to set one.
Description Resource Path Location Type Project has no default.properties file! Edit the project pro ...
- android的Project has no default.properties file! Edit the project properties to set one. 的解决
网上找来这种方法基本解决: 在我们导入Android工程时,有时候会出现如题所述的错误,打开工程目录可以看到,目录下的default.properties文件没有了或者多出了一个project.pro ...
- [Android Pro] android 混淆文件project.properties和proguard-project.txt
参考文档:http://blog.csdn.net/xueyepiaoling/article/details/8202359转载自:http://glblong.blog.51cto.com/305 ...
- Android 混淆文件project.properties和proguard-project.txt
参考文档:http://blog.csdn.net/xueyepiaoling/article/details/8202359 http://glblong.blog.51cto.com/305861 ...
- 关于android混淆文件project.properties和proguard-project.txt详解
一直不明白Android开发中的有些文件的具体作用,后来用到了,具体研究了一下,借鉴了一下网上的资料,最后总结下,方便以后查看! 老版本中有这么个文件default.properties,既然是老版本 ...
- AndroidManifest.xml的targetSdkVersion 与 project.properties中target
(1)minSdkVersion与maxSdkVersion :在安装程序的时候,如果目标设备的API < minSdkVersion,或者目标设备的API > maxSdkVersion ...
- Project has no project.properties file! Edit the project properties to set one.
解决办法: 右击项目,选择android tools-->fix project properties.然后重启eclipse即可.
- proguard-project.txt和project.properties混淆代码
[转]利用android proguard混淆代码 防止反编译,优化代码 网上虽然有很多相关博客,不过貌似都不是最新版的..于是百度+谷歌+github上的开源demo,终于成功的配置了androi ...
随机推荐
- 手机自动化测试:Appium源码之API(2)
手机自动化测试:Appium源码之API(2) TouchAction AppiumDriver的辅助类,主要针对手势操作,比如滑动.长按.拖动等.TouchAction的原理是讲一系列的动作放在 ...
- 漫谈PHP代码规范
前言 虽说PHP是世界上最好的语言,但是写出来的PHP代码却往往不是最美观的.究其原因,可能正式因为PHP简单易上手,适合快速迭代的特性,导致了我们沉浸在迅速完成需求迭代的窃喜中,却忘记了规范性.忽略 ...
- input是否checked与使用jquery的attr或prop方法无关
最近在项目中有这样一个需求,用户在下单时可以选择优惠券,也可取消选择,并且可以多次选择,取消. 这是一个典型的input标签checked功能,博主使用radio元素实现此需求,但是优惠券只能选中,不 ...
- net.sz.framework 框架 轻松搭建数据服务中心----读写分离数据一致性,滑动缓存
前言 前文讲述了net.sz.framework 框架的基础实现功能,本文主讲 net.sz.framework.db 和 net.sz.framework.szthread; net.sz.fram ...
- GPIO寄存器
GPIO寄存器描述 <STM32参考手册中文-p75> 1.端口配置低寄存器(GPIOx_CRL)(x = A...E)2.端口配置高寄存器(GPIOx_CRH)(x = A...E) 3 ...
- node.js系列(实例):原生node.js实现静态资源管理
/** * node入门之综合案例(一):简易路由 * @Author : by Ghost * @Date : 2016/07/11 * @Description : * 1.引入以下模块 * ht ...
- MySQL中字符串与数字比较的坑
公司项目代码中,某枚举字段数据库表中类型是char(1),在代码中,误以为是TINYINT,所以用数字筛选,后来发现结果不对.发现了一个现象,用数字0筛选会把所有的记录给筛选出来. 经过排查发现是在M ...
- JS存在性
var myObject = { a:2 }; ("a" in myObject);//true ("b" in myObject);//false myObj ...
- java集合的操作(set,Iterator)
集合的操作 Iterator.Collection.Set和HashSet关系 Iterator<——Collection<——Set<——HashSet Iterator中的方法: ...
- Display:table;妙用,使得左右元素高度相同
我们在设计网页的时候,为了左右能够分明一点,我们经常会在左边元素弄一个border-right,但是出现一个问题,如果左边高度比较小,这根线就短了,下面空了一部分,反正如果在右边的元素弄一个borde ...