Hallo Leute,
ich habe ein Programm geschrieben, in dem eine zip-Datei entpackt werden soll. Ich habe mich im www ein wenig umgesehen wie, aber ich kann nicht verstehen, wie man eine Zip-Datei an einen anderen ort entpackt. Könntet ihr mir vielleicht helfen? Danke im Voraus.
byte[] buffer = new byte[BUFFER_SIZE];
int len;
File file = new File("/name/der/zipdatei.zip");
File destinationPath = new File("/in/den/ordner/wirds/geschrieben");
ZipFile zipFile = new ZipFile(file, ZipFile.OPEN_READ);
Enumeration<? extends ZipEntry> zipEntries = zipFile.entries();
while(zipEntries.hasMoreElements()){
ZipEntry zipEntry = zipEntries.nextElement();
InputStream zipIn = zipFile.getInputStream(zipEntry);
File outFile = new File(destinationPath, zipEntry.getName());
OutputStream outStream = new FileOutputStream(outFile);
while((len = zipIn.read(buffer)) > 0){
outStream.write(buffer, 0, len);
}
outStream.close();
zipIn.close();
}
outStream = new FileOutputStream(outFile);
String respath = chooser.getSelectedFile().getAbsolutePath();
final int buflength = 1024;
byte[] buffer = new byte[buflength];
int len;
File usdir = new File(System.getProperty("user.dir"));
File file = new File(respath);
File destinationPath = usdir;
ZipFile zipFile;
try {
zipFile = new ZipFile(file, ZipFile.OPEN_READ);
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
Enumeration<? extends ZipEntry> zipEntries = zipFile.entries();
while(zipEntries.hasMoreElements()){
ZipEntry zipEntry = zipEntries.nextElement();
InputStream zipIn;
try {
zipIn = zipFile.getInputStream(zipEntry);
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
File outFile = new File(destinationPath, zipEntry.getName());
OutputStream outStream;
try {
outStream = new FileOutputStream(outFile);
} catch (FileNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try {
while((len = zipIn.read(buffer)) > 0){
try {
outStream.write(buffer, 0, len);
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
try {
outStream.close();
} catch (IOException e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
}
try {
zipIn.close();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}