Android: ZipFile() java.util.zip.ZipException: File too short to be a zip file: 0
I am working on a project (using Android Studio 3.1.4) that reads neural networks stored as .zip files for further use of DL4J in Android.
I’m trying to open this .zip file located in my project’s res\raw directory. To do this, I tried using the ZipFile() method in java.util.zip.
The following code throws an exception:
File model_file = new File(String.valueOf(this.getResources().openRawResource(R.raw.neuralnet))); ZipFile zipFile = new ZipFile(model_file);
“java.util.zip.ZipException: File too short to be a zip file: 0”
So I can’t load the model. Test on a simulated device running Android API 24
On API 26 exceptions are different:
java.io.FileNotFoundException: File doesn’t exist: [email protected]
Does anyone have experience with ZipFile() or loading neural network models with DL4J in Android?
Do you need something special in build.gradle?
Any comments are welcome!
I tried :
- Check the .zip file to make sure it exists.
- is just a container and that the files are not compressed by using 7Zip to archive the 3 contained files as .zip without compression
- Checked READ_EXTERNAL_STORAGE permissions, although I don’t think it’s needed
- Try using the full path instead of this.getResources().openRawResource(R.raw.neuralnet).
Ensure that .zip
I’m running android api > 23 and I’m requesting READ_EXTERNAL_STORAGE permissions at runtime.
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
Your problem is the way to open the file.
To open the original file, check the following link: