How can I list the contents of the res folder in Blackberry?

How can I list the contents of the res folder in Blackberry? For example, if res folder has four files, I want to get the names of those files in a String array.

Upvotes: 1

Views: 142

Answers (1)

Nate
Nate

Reputation: 31045

I would love to be wrong on this, but I'm not sure that you can do that. I've tried something similar before, and never found a solution.

I've thought about trying to get a reference to one known file in my res\ folder, or perhaps the top-level res directory itself. From there, I would enumerate the contents of the directory tree.

The problem is that doing

InputStream input = getClass().getResourceAsStream("/res/img/icon.png");

will give you an InputStream, which does not give you access to filesystem information (it's just a stream, which is an abstraction).

And, if you try to get a file connection

FileConnection conn = (FileConnection) Connector.open("local:///img/icon.png");

you'll be told that the Connector class doesn't support the local:/// protocol (I've also tried with the cod:/// URL scheme, with no luck).

Workaround

The only thing I suggest is that since your resource folders are read-only folders, you should be able to list out their contents at build time, and not have to do it inside your app at run time.

I don't know which build system you're using (e.g. Eclipse plugin, bb-ant-tools, JDE, etc.) but you could certainly write a desktop Java application to parse through your project's res/ folder and write the contents to an xml file, that would also be placed in your res/ folder.

Then, at run time, you could read the directory listing from the xml file.

Like I said, I'd love to know if there's a way to do this in the app, but if there's not, a pre-build script of some sort should work, too.

Upvotes: 1

Related Questions