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的更多相关文章

  1. 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 ...

  2. 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 ...

  3. android的Project has no default.properties file! Edit the project properties to set one. 的解决

    网上找来这种方法基本解决: 在我们导入Android工程时,有时候会出现如题所述的错误,打开工程目录可以看到,目录下的default.properties文件没有了或者多出了一个project.pro ...

  4. [Android Pro] android 混淆文件project.properties和proguard-project.txt

    参考文档:http://blog.csdn.net/xueyepiaoling/article/details/8202359转载自:http://glblong.blog.51cto.com/305 ...

  5. Android 混淆文件project.properties和proguard-project.txt

    参考文档:http://blog.csdn.net/xueyepiaoling/article/details/8202359 http://glblong.blog.51cto.com/305861 ...

  6. 关于android混淆文件project.properties和proguard-project.txt详解

    一直不明白Android开发中的有些文件的具体作用,后来用到了,具体研究了一下,借鉴了一下网上的资料,最后总结下,方便以后查看! 老版本中有这么个文件default.properties,既然是老版本 ...

  7. AndroidManifest.xml的targetSdkVersion 与 project.properties中target

    (1)minSdkVersion与maxSdkVersion :在安装程序的时候,如果目标设备的API < minSdkVersion,或者目标设备的API > maxSdkVersion ...

  8. Project has no project.properties file! Edit the project properties to set one.

    解决办法: 右击项目,选择android tools-->fix project properties.然后重启eclipse即可.

  9. proguard-project.txt和project.properties混淆代码

     [转]利用android proguard混淆代码 防止反编译,优化代码 网上虽然有很多相关博客,不过貌似都不是最新版的..于是百度+谷歌+github上的开源demo,终于成功的配置了androi ...

随机推荐

  1. WPF之路三:视频的播放

    同图片一样,把视频资源复制到文件夹路径下,修改资源属性复制到输出目录"始终复制",生成操作改为“内容”, 把<MediaElement  Name="myVid&q ...

  2. boostrap详情解毒

    详解Bootstrap表单组件 表单常见的元素主要包括:文本输入框.下拉选择框.单选框.复选框.文本域.按钮等.下面是不同的bootstrap版本: LESS:  forms.less SASS:  ...

  3. getline函数(精华版)

    在我的印象中,getline函数经常出现在自己的视野里,模糊地记得它经常用来读取字符串   .但是又对它的参数不是很了解,今天又用到了getline函数,现在来细细地总结一下:   首先要明白设计ge ...

  4. spring mvc mybatis集成踩的坑

    开园这么多年了也没写几篇文章,现在想想光看别人的也不行啊,咱也自己写写,就写这天我我在做spring mvc与mybatis的集成时遇到的问题 1 spring与mybatis的集成 这个相信大家都弄 ...

  5. folly教程系列之:future/promise

         attension:本文严禁转载. 一.前言 promise/future是一个非常重要的异步编程模型,它可以让我们摆脱传统的回调陷阱,从而使用更加优雅.清晰的方式进行异步编程.c++11中 ...

  6. 关于php 高并发解决的一点思路

    涉及抢购.秒杀.抽奖.抢票等活动时,为了避免超卖,那么库存数量是有限的,但是如果同时下单人数超过了库存数量,就会导致商品超卖问题.那么我们怎么来解决这个问题呢,我的思路如下(伪代码): sql1:查询 ...

  7. 初识ElasticSearch

    概述 Elasticsearch是一个基于Apache Lucene(TM)的开源搜索引擎.无论在开源还是专有领域,Lucene可以被认为是迄今为止最先进.性能最好的.功能最全的搜索引擎库. 分布式的 ...

  8. ADO.NET 获取SQL SERVER数据库架构信息

    1.确定可用字段数目 sqlDataReader类提供了FieldCount属性,可确定查询反悔了多少个字段. 2.确定返回行的数目 sqlDataReader中没有指示可用行的属性. 3.确定字段的 ...

  9. Cocos2d-x性能分析-Android版本之Gprof

    在 iOS 平台下我们可以用 Xcode 自带的 Profile 工具来测试我们程序的性能,Android 平台使用的 gprof 这里整理了一下具体的cocos2dx 使用gprof进行性能分析的具 ...

  10. 《JavaScript面向对象编程指南(第2版)》读书笔记(一)

    目录 一.对象 1.1 获取属性值的方式 1.2 获取动态生成的属性的值 二.数组 2.1 检测是否为数组 2.2 增加数组长度导致未赋值的位置为undefined 2.3 用闭包实现简易迭代器 三. ...