Как обрабатывать zipexception (неправильный пароль для файла: demo.zip) и отображать соответствующие сообщенияJAVA

Программисты JAVA общаются здесь
Anonymous
Как обрабатывать zipexception (неправильный пароль для файла: demo.zip) и отображать соответствующие сообщения

Сообщение Anonymous »

Since I'm new to Java, I have created a method to unzip password protected zip files, I have used zip4j library for unzipping the zip file,the code works fine when the password is correct, but when the password is wrong how to handle the ZipException(net.lingala.zip4j.exception.ZipException: net.lingala.zip4j.exception.ZipException: net.lingala.zip4j.exception.zipexception: неправильный пароль для файла: demo.zip) и отображение подходящего сообщения (неправильный пароль!). Пожалуйста, помогите, вот мой код. PrettyPrint-Override ">

Код: Выделить всё

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);
}
}



Подробнее здесь: https://stackoverflow.com/questions/543 ... play-appro

Вернуться в «JAVA»