views:

52

answers:

1

Doing Android 2.1 development. Can anybody explain to me why the following code generates a IOException and doesn't load the file? This exact code used to work, and as far as I can tell, it should still work. For reference, the Log.d() command correctly lists all files that I expect, and the files are correctly zipped into my .APK file.

        AssetManager assetManager = mContext.getAssets();
        String[] files = null;
        try
            {
            files = assetManager.list("meshes");
            for (int i = 0; i < files.length; i++)
                Log.d(TAG, files[i]);
            InputStream is = assetManager.open(files[0]);
            }
        catch (IOException e) 
            {
            Log.e(TAG, "Could not load '" + e.getMessage()+ "'!");
            }

Any ideas on why this breaks now? The files I'm trying to read are tiny (couple of bytes) binaries.

+1  A: 

Finally figured it out. Blatant user error, but couldn't see the forest for the trees. The list command doesn't include the directory name, the open command expects the full pathname. Duh :) The open command needs to build a string that includes both the directory name and the filename.

Drakestar
So, mark you answer as correct.
Cristian