Reading Properties Files in Android

This yet-to-be-self-identified blogger from Sweeden knows a thing or two about reading files from Android:

Reading Properties Files on Android (Investigation for microlog4android)

For reference, I’m reproducing a snippet of code he posted.  This will read from the /assets directory:

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();
}

And this will  read a properties file from the /raw directory:

// Read from the /res/raw directory
try {
    InputStream rawResource = resources.openRawResource(R.raw.micrologv2);
    Properties properties = new Properties();
    properties.load(rawResource);
    System.out.println("The properties are now loaded");
    System.out.println("properties: " + properties);
} catch (NotFoundException e) {
    System.err.println("Did not find raw resource: "+e);
} catch (IOException e) {
    System.err.println("Failed to open microlog property file");
}

JAD properties specific to RIM.

In addition to the normal J2ME properties that go into a JAD file (.jad), RIM has a set of properties that are specific to the RIM platform that go there too.  Here they are:

 

Properties of BlackBerry device application .jad files

The BlackBerry® Integrated Development Environment lets you create a dual-purpose .jad file to support the downloading of MIDlets onto BlackBerry devices and other wireless devices. To do this, create a .jad file that contains both the RIM-COD-URL and RIM-COD-Size attributes and the MIDlet-Jar-URL and MIDlet-Jar-Size attributes. On BlackBerry devices, download the .cod files; on other wireless devices, download the .jar files.
Required RIM attribute Description
RIM-COD-Creation-Time creation time of the .cod file
RIM-COD-Module-Dependencies list of modules that the .cod file requires
RIM-COD-Module-Name name of the module that the .cod file contains
RIM-COD-SHA1 SHA1 hash of the .cod file
RIM-COD-Size size (in bytes) of the .cod file
RIM-COD-URL URL from which the .cod file can be loaded
Optional RIM attribute Description
RIM-Library-Flags reserved for use by Research In Motion
RIM-MIDlet-Flags reserved for use by RIM
RIM-MIDlet-NameResourceBundle name of the resource bundle on which the BlackBerry device application depends
RIM-MIDlet-Position suggested position of the BlackBerry device application icon on the Home screen might not be the actual position of the icon on the Home screen

source: http://na.blackberry.com/eng/deliverables/7693/Attributes_for_jad_files_513047_11.jsp