import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Enumeration;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import java.util.zip.ZipInputStream;
import java.net.MalformedURLException;
import java.net.URL;
public class getZip {
// specify buffer size for extraction
static final int BUFFER = 5 * 1024;
public static void main(String[] args) {
try {
System.out.println("Example of ZIP file decompression.");
// Specify file to decompress
String inFileName = "http://www.gutenberg.org/feeds/catalog.rdf.zip";
// Specify destination where file will be unzipped
String destinationDirectory = ".";
URL url = new URL(inFileName);
InputStream in = url.openStream();
// File sourceZipFile = new File(inFileName);
File unzipDestinationDirectory = new File(destinationDirectory);
// Open Zip file for reading
ZipInputStream zipFile = new ZipInputStream(in);
ZipEntry entry;
while(((entry = zipFile.getNextEntry()) != null) && entry.getName().equals("catalog.rdf")) {
System.out.println("Extracting: " + entry.getName());
File destFile = new File(unzipDestinationDirectory, entry.getName());
BufferedOutputStream dest = new BufferedOutputStream(
new FileOutputStream(destFile), BUFFER);
// read and write until last byte is encountered
byte[] buff = new byte[BUFFER];
int n;
while ((n = zipFile.read(buff)) != -1) {
dest.write(buff, 0, n);
}
dest.flush();
dest.close();
// is.close();
}
zipFile.close();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
download and extract a zip in Java
2009.04.28. 15:29 kirunews
Szólj hozzá!
A bejegyzés trackback címe:
https://kirunews.blog.hu/api/trackback/id/tr431091619
Kommentek:
A hozzászólások a vonatkozó jogszabályok értelmében felhasználói tartalomnak minősülnek, értük a szolgáltatás technikai üzemeltetője semmilyen felelősséget nem vállal, azokat nem ellenőrzi. Kifogás esetén forduljon a blog szerkesztőjéhez. Részletek a Felhasználási feltételekben és az adatvédelmi tájékoztatóban.
Nincsenek hozzászólások.