I am working on a project (Using Android Studio 3.1.4) that reads in a neural network that is stored as a .zip file, for further use with DL4J in Android.
I am trying to open this .zip file located in my projects res\raw directory. For this I am trying to use the ZipFile() method from java.util.zip.
Screenshot of location of neuralnet.zip
Problem:
Following code throws an exception:
File model_file = new File(String.valueOf(this.getResources().openRawResource(R.raw.neuralnet)));
ZipFile zipFile = new ZipFile(model_file);
Exception:
"java.util.zip.ZipException: File too short to be a zip file: 0"
Therefore I cannot load the model. Testing this on a simulated device running Android API 24
On API 26 the exception is different:
java.io.FileNotFoundException: File doesn't exist: android.content.res.AssetManager$AssetInputStream@ddde727
Does someone have experience with the use of ZipFile(), or with loading neuralnetwork models using DL4J in Android?
Could there be something special be required in the build.gradle?
Any input is appreciated!
What I have tried:
Android permissions: I am running android api > 23, and I am requesting the READ_EXTERNAL_STORAGE permission at runtime.
Manifest includes:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
Thanks,
Mo
Your problem is the way of file opening.
For open a raw file look at below links:
https://developer.android.com/guide/topics/resources/providing-resources