1. Put your config file inside lib directory populated on aar file.
2. Using:
InputStream in=getClass().getClassLoader().getResourceAsStream("Test.properties");
which will load the property file into memory.
3. for instance:
public String testResourceReader() {
Properties p=new Properties();
InputStream in=getClass().getClassLoader().getResourceAsStream("Test.properties");
try {
p.load(in);
} catch (IOException e) {
e.printStackTrace();
}
return p.toString();
}
Result:
<ns:testResourceReaderResponse>
<ns:return>{name=test name, file=file1}</ns:return>
</ns:testResourceReaderResponse>
加载属性文件示例
本文介绍了一种在Java中从类路径加载属性文件的方法。通过使用`getClass().getClassLoader().getResourceAsStream()`方法来读取位于类路径下的`Test.properties`文件,并将其内容加载到内存中的`Properties`对象里。

被折叠的 条评论
为什么被折叠?



