zipファイルをAsyncTaskで解凍しようとしているのですが、
途中で、FileNotFoundExceptionが呼ばれて失敗します。
※zipファイルの中身は100枚程のjpgです。
機種によって成功する場合と失敗する場合があります。
また、失敗する機種でも、毎回失敗するわけではなく、成功する時もあります。
解凍部分のコードは、以下のようになっています。
protected Boolean doInBackground(Void... params) { try { ZipInputStream zipInputStream = new ZipInputStream( new FileInputStream(file.getPath())); ZipEntry entry = null; while ((entry = zipInputStream.getNextEntry()) != null) { String fileName = entry.getName(); FileOutputStream os = new FileOutputStream(new File( file.getParent(), fileName)); byte[] buffer = new byte[2048]; int length = 0; while ((length = zipInputStream.read(buffer)) > 0) { os.write(buffer, 0, length); } os.close(); zipInputStream.closeEntry(); } zipInputStream.close(); } catch (Exception e) { e.printStackTrace(); return false; } return true; }
エラーログは以下です。
01-26 15:24:22.047 697-745/test W/System.err: java.io.FileNotFoundException: /storage/emulated/0/Android/data/test/files/test1.jpg: open failed: ENOENT (No such file or directory)
何か、良い解決方法はないでしょうか?
ご回答頂けると助かります。