public static boolean unZipFile(String pathName, String toPath)
{
File desFile = null;
try
{
Log.v("unZipFile", "unzip start");
@SuppressWarnings("resource")
ZipFile zf = new ZipFile(pathName);
for (Enumeration<?> entries = zf.entries(); entries.hasMoreElements();)
{
ZipEntry entry = ((ZipEntry) entries.nextElement());
if (entry.isDirectory())
{
continue;
}
InputStream in = zf.getInputStream(entry);
String strEntry = entry.getName();
String strEntryFilename = strEntry.substring(strEntry.lastIndexOf("/") + 1);
String filePath = toPath + File.separator + strEntryFilename;
desFile = new File(filePath);
OutputStream out = new FileOutputStream(desFile);
byte buffer2[] = new byte[1024 * 1024];
int len = -1;
while ((len = in.read(buffer2)) != -1)
{
out.write(buffer2, 0, len);
Log.v("unZipFile", "unZipFile len =" + len);
}
out.close();
in.close();
//FileUtils.renameFile(desFile.getAbsolutePath(), filePath);
}
Log.v("unZipFile", "unzip finish");
return true;
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
return false;
}
finally
{
//FileUtils.deleteFile(new File(pathName));
}
}
{
File desFile = null;
try
{
Log.v("unZipFile", "unzip start");
@SuppressWarnings("resource")
ZipFile zf = new ZipFile(pathName);
for (Enumeration<?> entries = zf.entries(); entries.hasMoreElements();)
{
ZipEntry entry = ((ZipEntry) entries.nextElement());
if (entry.isDirectory())
{
continue;
}
InputStream in = zf.getInputStream(entry);
String strEntry = entry.getName();
String strEntryFilename = strEntry.substring(strEntry.lastIndexOf("/") + 1);
String filePath = toPath + File.separator + strEntryFilename;
desFile = new File(filePath);
OutputStream out = new FileOutputStream(desFile);
byte buffer2[] = new byte[1024 * 1024];
int len = -1;
while ((len = in.read(buffer2)) != -1)
{
out.write(buffer2, 0, len);
Log.v("unZipFile", "unZipFile len =" + len);
}
out.close();
in.close();
//FileUtils.renameFile(desFile.getAbsolutePath(), filePath);
}
Log.v("unZipFile", "unzip finish");
return true;
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
return false;
}
finally
{
//FileUtils.deleteFile(new File(pathName));
}
}