日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 运维知识 > Android >内容正文

Android

Android解压ZIP

發布時間:2024/3/26 Android 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Android解压ZIP 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

采用流的方式處理大文件

1.CheckedInputStream,這個是一個檢驗流

CheckedInputStream cis = new CheckedInputStream(new FileInputStream(srcFile), new CRC32());

2.再將這個檢驗流轉換成Zip輸入流:

ZipInputStream zis = new ZipInputStream(cis);
3.獲取zip流的實體:

while ((zipEntry = zis.getNextEntry()) != null)
4.然后用字節輸出流的方式:

BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(destFile));
? ? ? ? int len;
? ? ? ? byte[] buff = new byte[DEFAULT_BUFF_SIZE];
? ? ? ? while ((len = zis.read(buff, 0 ,DEFAULT_BUFF_SIZE)) != -1) {
? ? ? ? ? ? bos.write(buff, 0, len);
? ? ? ? }

完整代碼:?public static File decompress(File srcFile, File destFile) throws Exception {
? ? ? ? while (destFile.exists()) {
? ? ? ? ? ? destFile = new File(destFile.getAbsolutePath()+"1");
? ? ? ? }
? ? ? ? CheckedInputStream cis = new CheckedInputStream(new FileInputStream(srcFile), new CRC32());
? ? ? ? ZipInputStream zis = new ZipInputStream(cis);
? ? ? ? doDecompress(destFile, zis);
? ? ? ? zis.close();
? ? ? ? return destFile;
? ? }
?
? ? private static void doDecompress(File destFile, ZipInputStream zis) throws Exception {
? ? ? ? ZipEntry zipEntry = null;
? ? ? ? while ((zipEntry = zis.getNextEntry()) != null) {
? ? ? ? ? ? String dir = destFile.getPath() + File.separator + zipEntry.getName();
? ? ? ? ? ? File dirFile = new File(dir);
? ? ? ? ? ? fileProber(dirFile);
? ? ? ? ? ? if (zipEntry.isDirectory()) {
? ? ? ? ? ? ? ? dirFile.mkdirs();
? ? ? ? ? ? } else {
? ? ? ? ? ? ? ? doDecompressFile(dirFile, zis);
? ? ? ? ? ? }
? ? ? ? ? ? zis.closeEntry();
? ? ? ? }
? ? }
?
? ? private static void doDecompressFile(File destFile, ZipInputStream zis) throws Exception {
? ? ? ? BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(destFile));
? ? ? ? int len;
? ? ? ? byte[] buff = new byte[DEFAULT_BUFF_SIZE];
? ? ? ? while ((len = zis.read(buff, 0 ,DEFAULT_BUFF_SIZE)) != -1) {
? ? ? ? ? ? bos.write(buff, 0, len);
? ? ? ? }
? ? ? ? bos.close();
? ? }
?
?
原文鏈接:https://blog.csdn.net/howlaa/article/details/124384800
?

總結

以上是生活随笔為你收集整理的Android解压ZIP的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。