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

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

如何處理 ZipException(文件密碼錯(cuò)誤:Demo.zip)并顯示適當(dāng)?shù)南?/h1>

    由于我是 Java 新手,我創(chuàng)建了一種解壓縮受密碼保護(hù)的 zip 文件的方法,我使用 zip4j 庫(kù)來解壓縮 zip 文件,密碼正確時(shí)代碼工作正常,但密碼錯(cuò)誤時(shí)如何處理ZipException(net.lingala.zip4j.exception.ZipException:net.lingala.zip4j.exception.ZipException:net.lingala.zip4j.exception.ZipException:文件密碼錯(cuò)誤:Demo.zip)并顯示適當(dāng)?shù)南ⅲ艽a錯(cuò)誤! )。請(qǐng)幫助,這是我的代碼。import net.lingala.zip4j.core.ZipFile;import net.lingala.zip4j.exception.ZipException;import net.lingala.zip4j.model.ZipParameters;import net.lingala.zip4j.util.Zip4jConstants;public class UnunzipDemo{    public void unzipFilesWithPassword(String sourceZipFilePath,String extractedZipFilePath,String password){        try {            ZipFile zipFile = new ZipFile(sourceZipFilePath);            if (zipFile.isEncrypted()) {                zipFile.setPassword(password);            }            zipFile.extractAll(extractedZipFilePath);            System.out.println("Done");        }        catch (ZipException e) {            e.printStackTrace();        }    }    public static void main(String[] args) {        String sourceZipFilePath="E:/MyFiles/Files/Zip/Demo.zip";        String extractedZipFilePath="E:/MyFiles/Files/Unzip/";        String password="JOEL"; //Correct Password        UnunzipDemo unzipDemo=new UnunzipDemo();        unzipDemo.unzipFilesWithPassword(sourceZipFilePath,extractedZipFilePath,password);    }}
查看完整描述

2 回答

?
暮色呼如

TA貢獻(xiàn)1853條經(jīng)驗(yàn) 獲得超9個(gè)贊

也許您可以從控制臺(tái)讀取密碼。例如:


    private static String password = "123";


    public static void main(String[] args) {


        // read the input password from console

        // if you have UI, maybe you can read it from some way.

        Scanner sc = new Scanner(System.in);

        String inputPassword = sc.next();

        while (true) {

            //do something...

            try {

                unzip(inputPassword);

                break;

            } catch (Exception e) {

                inputPassword = sc.next();

            }


        }

    }


    private static void unzip(String inputPassword) {

        if (inputPassword.equals(password)) {

            //unzip

        } else {

            // just demo. In your case, this is ZipException

            throw new IllegalArgumentException("wrong password");

        }

    }


查看完整回答
反對(duì) 回復(fù) 2022-05-25
?
FFIVE

TA貢獻(xiàn)1797條經(jīng)驗(yàn) 獲得超6個(gè)贊

您還可以檢查錯(cuò)誤代碼。


public void unzipFilesWithPassword(String sourceZipFilePath,String extractedZipFilePath,String password){

    try {

        ZipFile zipFile = new ZipFile(sourceZipFilePath);

        if (zipFile.isEncrypted()) {

            zipFile.setPassword(password);

        }

        zipFile.extractAll(extractedZipFilePath);

        System.out.println("Done");

    }

    catch (ZipException e) {

        if (e.getCode == ZipExceptionConstants.WRONG_PASSWORD) {

           // Handle wrong password scenario

           System.out.println("Wrong password");

        } else {

           //Handle other exception scenario - printing out error messages?

        }

    }


查看完整回答
反對(duì) 回復(fù) 2022-05-25
  • 2 回答
  • 0 關(guān)注
  • 177 瀏覽
慕課專欄
更多

添加回答

了解更多

舉報(bào)

0/150
提交
取消
微信客服

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

幫助反饋 APP下載

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

公眾號(hào)

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