From this question, I know how to obtain Properties within an Android Application.
However, if I want to write an Android Library, and intend to read a properties file (say myconfig.properties
, how can I do so?
Given that the Android Library (e.g. it's called "myAndroidLib" ) has android-support-v4.jar
, and this library is imported to an Android Application. Also given that myconfig.properties
exists.
I found a piece of code in the Internet, but this works only within Android:
Resources resources = this.getResources();
AssetManager assetManager = resources.getAssets();
// Read from the /assets directory
try {
InputStream inputStream = assetManager.open("microlog.properties");
Properties properties = new Properties();
properties.load(inputStream);
System.out.println("The properties are now loaded");
System.out.println("properties: " + properties);
} catch (IOException e) {
System.err.println("Failed to open microlog property file");
e.printStackTrace();
}