ERLEDIGT
NEIN
NEIN
ANTWORTEN
9
9
ZUGRIFFE
946
946
EMPFEHLEN
-
Hallo Leute,
ich habe da folgendes Problem. Und zwar muss ich ein Zip Archiv von einer URL
runterladen.
Soweit OK.
Code :1 2 3 4
URL url = new URL(inurl); InputStream instr = url.openStream(); System.out.println(url.getProtocol()+": "+url.getHost()+url.getPath()); ZipInputStream inzip = new ZipInputStream(instr);
Um mir nun die Arbeit zu erleichetern habe ich hier im Forum
das gefunden:
http://www.tutorials.de/forum/java/2...entpacken.html
Mit Hilfe diese Beispiels bin ich sweit gekommen,
dass ich die Verzeichnisstruktur aus dem Archiv bekomme und diese auf die
Platte schreibe.
Problem gibt es aber bei den einzelnen Dateien im Archiv,
die bekomme ich nicht geschrieben.
Hilfe........
-
Hallo,
was genau funktioniert denn nicht?
Kommt eine Fehlermeldung?
Zeigst du mal den Code?
Gruß
SaschaEs ist schwer Allwissend zu sein. Aber ich komme damit klar. ;-)
-
hallo,
meine problem besteht darin, dass ich aktuell wie im beispiel
http://www.tutorials.de/forum/java/2...entpacken.html
vorgehe.
ich hole mir über die url ein zip file und entpacke dieses sogleich in ein verzeichnis,
hierbei umss ich leider das zip file in einer tmp datei ablegen.
das möchte ich umgehen und nur über stream arbeiten.
-
11.11.09 12:50 #4
- Registriert seit
- Jun 2002
- Ort
- Saarbrücken (Saarland)
- Beiträge
- 9.724
- Blog-Einträge
- 29
Hallo,
schau mal hier:
Code java:1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
package de.tutorials; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.net.URL; import java.nio.channels.Channels; import java.util.Iterator; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; import com.google.common.collect.AbstractIterator; public class ZipArchiveExtractor { /** * @param args */ public static void main(String[] args) throws Exception { File destDir = new File("/tmp/goog.collect.src"); final ZipInputStream zipIn = new ZipInputStream(new URL("http://localhost:8000/src-1.0-rc3.zip").openStream()); Iterator<? extends ZipEntry> zipEntries = new AbstractIterator<ZipEntry>() { @Override protected ZipEntry computeNext() { ZipEntry next = null; try { next = zipIn.getNextEntry(); if (next == null) { next = endOfData(); } } catch (IOException e) { next = endOfData(); } return next; } }; while (zipEntries.hasNext()) { ZipEntry zipEntry = zipEntries.next(); String entryName = zipEntry.getName(); System.out.println(entryName); if (zipEntry.isDirectory()) { File dir = new File(destDir, entryName); if (!dir.exists()) { if (!dir.mkdirs()) { throw new RuntimeException("Cannot create directory: " + dir); } } } else { FileOutputStream fos = null; try { File file = new File(destDir, entryName); System.out.println(file); fos = new FileOutputStream(file); fos.getChannel().transferFrom(Channels.newChannel(zipIn), 0, zipEntry.getSize()); } catch (Exception e) { e.printStackTrace(); } finally { if (fos != null) { fos.close(); } } } zipIn.closeEntry(); } zipIn.close(); } }
Gruß TomJava rocks!
How to become a good Java Programmer?
Does IT in Java and .Net
The only valid measurement of code quality: WTFs / minute
Blog
Xing
Twitter
-
ja vielen dank,
finde aber
com.google.common.collect.AbstractIterator
nicht zum runterlade
-
hi tom,
ja dank klapp bis auf die kleinigkeit,
dass die entpackten dateien leer sind.
-
11.11.09 13:55 #7
- Registriert seit
- Jun 2002
- Ort
- Saarbrücken (Saarland)
- Beiträge
- 9.724
- Blog-Einträge
- 29
Hallo,
seltsam bei mir funktioniert das so einwandfrei (Ubuntu Linux 9.10 / OpenJDK 1.6, 1.6.0_0-b16) ... haben die Daten denn überhaupt Inhalt, wenn du das Zip Archiv von der Quelle manuell runterlädst?
Gruß TomJava rocks!
How to become a good Java Programmer?
Does IT in Java and .Net
The only valid measurement of code quality: WTFs / minute
Blog
Xing
Twitter
-
hallo tom,
bei mir sieht die quelle "url" wie folgt aus
"http://pgrc-35.ipk-gatersleben.de/bfiler-web/BFileDownloadServlet?table_name=gcc_images&pk_column=tab_id&pk_value=6,12,34,1,2,3,55,66,1,2,3,4,5,7 ,8,9,10&bfile_column=thumbs&calling_user=GCC"
die entsprechende zip datei wird mittels eines servlets erzeug.........
das beispiel
http://www.tutorials.de/forum/java/2...entpacken.html
funktioniert.
-
hi tom,
ich habe es mit einigen änderungen hin bekommen.
Code :1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67
import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; import java.util.Iterator; import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; import com.google.common.collect.AbstractIterator; public class LimsZipExtractor{ public LimsZipExtractor(String inurl) throws MalformedURLException, IOException{ extract(inurl); }; private void extract(String inurl) throws MalformedURLException, IOException{ File destDir = new File("u:/test/"); // noch weg byte[] buffer = new byte[16384]; final ZipInputStream zipIn = new ZipInputStream(new URL(inurl).openStream()); Iterator<? extends ZipEntry> zipEntries = new AbstractIterator<ZipEntry>() { protected ZipEntry computeNext() { ZipEntry next = null; try { next = zipIn.getNextEntry(); if (next == null) { next = endOfData(); } } catch (IOException e) { next = endOfData(); } return next; } }; while (zipEntries.hasNext()) { ZipEntry zipEntry = zipEntries.next(); String entryName = zipEntry.getName(); System.out.println(entryName); if (zipEntry.isDirectory()) { File dir = new File(destDir, entryName); if (!dir.exists()) { if (!dir.mkdirs()) { throw new RuntimeException("Cannot create directory: " + dir); } } } else { BufferedOutputStream bos = new BufferedOutputStream( new FileOutputStream(new File(destDir, entryName))); int len =0; BufferedInputStream bis = new BufferedInputStream(zipIn); while ((len = bis.read(buffer)) != -1) { bos.write(buffer, 0, len); } bos.close(); zipIn.closeEntry(); } } ; };
-
hallo,
leider noch eine frage,
wie bekomme ich heraus wiele entries im stream sind
Code :1 2 3 4 5 6
int count=0; while(zipIn.getNextEntry() !=null){ count++; } System.out.println(count);
macht nur eine endlosschleife.......
Ähnliche Themen
-
Zip entpacken
Von Peter86 im Forum .NET CaféAntworten: 15Letzter Beitrag: 09.10.11, 14:27 -
zip entpacken
Von MiRaMC im Forum JavaAntworten: 11Letzter Beitrag: 08.08.11, 19:54 -
zip entpacken
Von Sturm im Forum PHPAntworten: 3Letzter Beitrag: 09.01.07, 19:53 -
*.gz entpacken
Von ChuloGT im Forum PHPAntworten: 2Letzter Beitrag: 02.11.04, 13:53 -
Entpacken von .zip
Von rauchmelder im Forum PHPAntworten: 1Letzter Beitrag: 05.09.04, 19:31





Zitieren



Login




