Wie identifiziere ich eine Zip -Datei in Java?
Posted: 05 Apr 2025, 11:17
Ich möchte mein Archiv identifizieren, unabhängig davon, ob es sich um ZIP oder rar handelt. Aber das Problem, das ich Laufzeitfehler erhalte, bevor ich meine Datei validieren kann. Ich möchte benutzerdefinierte Benachrichtigung erstellen: < /p>
public class ZipValidator {
public void validate(Path pathToFile) throws IOException {
try {
ZipFile zipFile = new ZipFile(pathToFile.toFile());
String zipname = zipFile.getName();
} catch (InvalidZipException e) {
throw new InvalidZipException("Not a zip file");
}
}
}
< /code>
Im Moment habe ich Laufzeitfehler: < /p>
Java.util.zip.zipexception: Fehler in der Öffnen von ZIP -Datei < /p> < /> < /blockquote>
public class ZipValidator {
public void validate(Path pathToFile) throws IOException {
try {
ZipFile zipFile = new ZipFile(pathToFile.toFile());
String zipname = zipFile.getName();
} catch (InvalidZipException e) {
throw new InvalidZipException("Not a zip file");
}
}
}
< /code>
Im Moment habe ich Laufzeitfehler: < /p>
Java.util.zip.zipexception: Fehler in der Öffnen von ZIP -Datei < /p> < /> < /blockquote>