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 ...
随机推荐
- Java类修饰符
- Myeclipse8.5开发-程序发布
1.新建focus.xml文件. 2.添加如下内容 <Context path="/focus" docBase="F:\Workspaces\MyEcli ...
- com.android.ide.common.process.PrecessException:org.gradle.process....finished with non-zero exit value 1
1.问题描述: 如图,在生成apk文件时出现如下错误, 2.原因分析: 我在网上搜了很多类似的问题,但试了又试也没有解决.然后我想上次编译时都没有出错,应该是最近的操作导致的错误. 3.解决办法: 把 ...
- Hibernate(四)之对象状态及一级缓存
一.Hibernate中的对象状态 1.1.瞬时态(临时态) 没有与Hibernate产生关联 与数据库中的记录没有产生关联(有关联就是与数据库中表的id相对应) 获得:一般都只直接创建(new) 瞬 ...
- 前馈神经网络-反向传播(Back Propagation)公式推导走读
构造:输入神经元个数等于输入向量维度,输出神经元个数等于输出向量维度.(x1=(1,2,3),则需要三个输入神经元) 一 前向后传播 隐层:
- SQL Server函数---Union与Union All的区别
SQL Server函数---Union与Union All的区别 如果我们需要将两个select语句的结果作为一个整体显示出来,我们就需要用到union或者union all关键字.union(或称 ...
- jQuery插件制作
模板:(function($){ $.fn.plugins=function(options){ var defaults = { } var options = $.extend(defaults, ...
- CF #349 div1 B. World Tour
题目链接:http://codeforces.com/problemset/problem/666/B 大意是给一张有向图,选取四个点,使得走这四个点,任意两个点之间走最短路,总距离最长. 3000个 ...
- glup/grunt,browserify / webpack等的比较
gulp/grunt的比较: Gulp / Grunt 是一种工具,能够优化前端工作流程.比如自动刷新页面.combo.压缩css.js.编译less等等.简单来说,就是使用Gulp/Grunt,然后 ...
- dotnetcore中的IOptionsSnapshot<>的自动更新原理
1.首先讲讲ChangeToken.OnChange方法: 原理是给一个CancellationToken注册一个消费者委托,调用CancellationToken的Cancel的时候会调用这个Can ...