I have an UnZip class to get images from a database
class UnZip extends AsyncTask<String, Integer, String> {
private String _mArchivePath;
private String _mOutPutStream;
private int per;
public UnZip(String mArchivePath,String mOutPutStream) {
_mArchivePath = mArchivePath;
_mOutPutStream = mOutPutStream;
}
@Override
protected String doInBackground(String... params) {
// TODO Auto-generated method stub
InputStream inputstream;
ZipInputStream zipinputstream;
try {
String filename;
inputstream = new FileInputStream(_mArchivePath);
zipinputstream = new ZipInputStream(new BufferedInputStream(inputstream));
ZipEntry mZipEntry;
byte[] buffer = new byte[32*1024];
int count;
while ((mZipEntry = zipinputstream.getNextEntry()) != null) {
Log.v("Decompress", "Unzipping " + mZipEntry.getName());
filename = mZipEntry.getName();
per++;
publishProgress(per);
if (mZipEntry.isDirectory()) {
File fmd = new File(_mOutPutStream + filename);
fmd.mkdirs();
continue;
}
FileOutputStream fileoutputstream = new FileOutputStream(_mOutPutStream + filename);
while ((count = zipinputstream.read(buffer)) != -1) {
fileoutputstream.write(buffer, 0, count);
}
fileoutputstream.close();
zipinputstream.closeEntry();
}
zipinputstream.close();
} catch (IOException e) {
e.printStackTrace();
}
return null;
It works great with a database.zip containing images(32MB~) but when I tried it with the same database.zip but with some images extra(43MB~) it gives me this error:
03-03 23:42:00.200: V/Decompress(11593): Unzipping /database/weed/ak_47_1.jpg
03-03 23:42:00.202: W/System.err(11593): java.io.FileNotFoundException: /storage/emulated/0/unzipped/database/weed/ak_47_1.jpg: open failed: ENOENT (No such file or directory)
03-03 23:42:00.204: W/InputMethodManagerService(584): Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@cce61f3 attribute=android.view.inputmethod.EditorInfo@aa9eeb0, token = android.os.BinderProxy@2db5667
I found the problem, it comes when I try to unzip a file with subfolders, if the subfolders don't exist the app gives me this error. Momentarily I changed the main code, so when the app starts it automatically creates the folders, because I know the structure of the zip, but if I want to use another zip what can I do?