Java本身就有處理Zip/Unzip的API.見底下程式碼:
public void unZip(InputStream is, String outPathString) { try { ZipInputStream Zis = new ZipInputStream(is); ZipEntry zipEntry; String szName = ""; while ((zipEntry = Zis.getNextEntry()) != null) { szName = zipEntry.getName(); if (zipEntry.isDirectory()) { File folder = new File(outPathString + File.separator + szName); folder.mkdirs(); } else { FileOutputStream out=new FileOutputStream(outPathString+ File.separator+szName); int len; byte[] buffer = new byte[1024]; while ((len = inZip.read(buffer)) != -1) { out.write(buffer, 0, len); out.flush(); } out.close(); } } Zis.close(); } catch (Exception e) {} }
沒有留言:
張貼留言