1

I'm trying to read data from a raw resource file on Android (in Java). For some reason, inStream.read(txt) is causing the exception to be thrown. Can anybody tell me what I'm doing wrong? Is there a permission I need to set?

try
{
        resourceId = R.raw.testmodel;
    if( resourceId==0 )
        return false; // invalid id

    InputStream inStream = context.getResources().openRawResource(resourceId);

    if( inStream==null )
        return false;

    byte[] txt = new byte[512];
    inStream.read(txt);
    //Toast.makeText(context,new String(txt),Toast.LENGTH_LONG).show();
    inStream.close();
}catch(Exception e)
{
    Toast.makeText(context,"strange exception",Toast.LENGTH_LONG).show();
    return false;
}
user980058
  • 511
  • 7
  • 18

1 Answers1

1

There is 1MB limit on assets and raw data in compressed apk files.

The limitation removed on version 2.3.

Possible workarounds are 1) splitting the file into 1MB chunks. 2) give the filename an extension of "mp3". The files with some specific extensions are not compressed by default, and thus are not subject to the limitation of "compressed" assets. The extension "mp3" is among the exceptions.

For more information:

https://stackoverflow.com/questions/2860157/load-files-bigger-than-1m-from-assets-folder

https://stackoverflow.com/questions/1273300/ioexception-while-reading-from-inputstream

Community
  • 1
  • 1