3

I am really stuck with this one.

I am trying to copy a file from the Assets folder of the apk to a local file. This WORKS in API Level 11, but NOT in API level 7. The tests are run on the emulator. API level 11 and above have also been tested successfully on a device.

UPDATE: I have tested with API Level 10 and it works fine. Therefore this issue is only applicable to API Level 7 (and possibly 8 and 9).

I am doing the following:

  1. Get the AssetManager - OK
  2. Open the InputStream - OK (no exception but not sure this works well)
  3. Open the FileOutputStream -OK
  4. Instantiate a byte[] to read data in (with size 1024) - OK
  5. Read the data from the asset into the byte[] - IOException is thrown without any details.

Below is the code:

InputStream dbFromApk = null; 
OutputStream dbout = null;

//1. Get the AssetManager
AssetManager am = this.getAssets();

//The line below is only a test - see bottom of the post how I used it
String[] files = am.list("");

//2. Open the InputStream - following this InputStream is no longer null
dbFromApk = this.getAssets().open(DB_FILENAME, AssetManager.ACCESS_STREAMING);

//3. Create the FileOutputStream
dbout = new FileOutputStream(dbFile);

//4. Instantiate the buffer to read data into
byte[] buffer = new byte[1024];

int bytesRead = 0;

//5. Read data - IOException is thrown - No further details in the exception
bytesRead = dbFromApk.read(buffer);

When I put the debugger and inspect the files array, I get an Eclipse error:

'JDI thread evaluations' has encountered a problem. 
Exception processing async thread queue
java.lang.UnsupportedOperationException

Inspecting the same variable when running at API level 11 works fine.

Lefteris
  • 873
  • 2
  • 8
  • 29

0 Answers0