第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何從內(nèi)部存儲中提取 zip 文件?

如何從內(nèi)部存儲中提取 zip 文件?

有只小跳蛙 2021-12-22 19:10:30
我想做一個項目來下載文件和提取文件。我嘗試修復(fù)它很長時間。請查看我的代碼并幫助我,或者有人告訴我如何下載文件和解壓 zip 文件。在文件“download.zip”中包含 5 個視頻文件。我使用Sreedev R 的Class Decompresspublic class MainActivity extends AppCompatActivity {private static String dirPath, dirPath2;final String URL1 = "http://webmaster.com/01/defualt.zip";@Overrideprotected void onCreate(Bundle savedInstanceState) {    super.onCreate(savedInstanceState);    setContentView(R.layout.activity_main);    dirPath = Utils.getRootDirPath(getApplicationContext());    dirPath2 = Utils.getRootDirPath(getApplicationContext())+"Unzip";    init();    onClickListenerOne();    Decompress unzip = new Decompress(dirPath+"/download.zip",dirPath2);    unzip.unzip();}解壓類public class Decompress {    private String zip;    private String loc;    public Decompress(String zipFile, String location) {        zip = zipFile;        loc = location;        dirChecker("");    }    public void unzip() {        try  {            FileInputStream fin = new FileInputStream(zip);            ZipInputStream zin = new ZipInputStream(fin);            ZipEntry ze = null;            while ((ze = zin.getNextEntry()) != null) {                Log.v("Decompress", "Unzipping " + ze.getName());                if(ze.isDirectory()) {                    dirChecker(ze.getName());                } else {                    FileOutputStream fout = new FileOutputStream(loc + ze.getName());                    for (int c = zin.read(); c != -1; c = zin.read()) {                        fout.write(c);                    }                    zin.closeEntry();                    fout.close();                }            }            zin.close();        } catch(Exception e) {            Log.e("Decompress", "unzip", e);        }    }    private void dirChecker(String dir) {        File f = new File(loc + dir);        if(!f.isDirectory()) {            f.mkdirs();        }    }}
查看完整描述

1 回答

?
森林海

TA貢獻2011條經(jīng)驗 獲得超2個贊

解決方案


您可以使用zip4j來提取 ZIP 文件。


public class Decompress {

    private String zip;

    private String loc;


    public Decompress(String zipFile, String location) {

        zip = zipFile;

        loc = location;


        dirChecker();

    }


    private void dirChecker() {

        File f = new File(loc);


        if(!f.isDirectory()) {

            f.mkdirs();

        }

    }


    public void unzip() {

        try {

            ZipFile zipFile = new ZipFile(zip);

            List<FileHeader> fileHeaders = zipFile.getFileHeaders();

            for (FileHeader fileHeader : fileHeaders) {

                String fileName = fileHeader.getFileName();


                if (fileName.contains("\\")) {

                    fileName = fileName.replace("\\", "\\\\");

                    String[] Folders = fileName.split("\\\\");

                    StringBuilder newFilepath = new StringBuilder();

                    newFilepath.append(loc);

                    for (int i = 0; i < Folders.length - 1; i++) {

                        newFilepath.append(File.separator);

                        newFilepath.append(Folders[i]);

                    }

                    zipFile.extractFile(fileHeader, newFilepath.toString(), null, Folders[Folders.length - 1]);

                } else {

                    zipFile.extractFile(fileHeader, loc);

                }

            }


        } catch (Exception e) {

            e.printStackTrace();

        }

    }

}


查看完整回答
反對 回復(fù) 2021-12-22
  • 1 回答
  • 0 關(guān)注
  • 193 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號