Article View: es.comp.lenguajes.java
Article #29073Junzip
From: Juan Pedro Barbancho Manchon
Date: Mon, 02 Feb 1998 00:00
Date: Mon, 02 Feb 1998 00:00
88 lines
3488 bytes
3488 bytes
Hola,
Este es para descomprimir un fichero.zip
JuanP
import java.io.*;
import java.util.zip.*;
import java.security.*;
import java.util.Enumeration;
class zip{
static FileInputStream fis;
public static void main(String[] args) {
try {
ZipFile zip = new ZipFile(args[0]);
for (Enumeration e = zip.entries() ; e.hasMoreElements() ;)
{
ZipEntry zipfile = (ZipEntry) e.nextElement();
System.out.println("Inicio");
System.out.println("Comment" + zipfile.getComment());
// Returns the comment string for the entry, or null if none.
System.out.println("Compresed" + zipfile.getCompressedSize() );
// Returns the compressed size of the entry data, or -1 if not known.
System.out.println("CRC" + zipfile.getCrc() );
// Returns the CRC-32 checksum of the uncompressed entry data, or -1 if
not known.
System.out.println("Extra" + zipfile.getExtra() );
// Returns the extra field data for the entry, or null if none.
System.out.println("Method" + zipfile.getMethod() );
// Returns the compression method of the entry, or -1 if not specified.
System.out.println("Name" + zipfile.getName());
// Returns the name of the entry.
System.out.println("Size" + zipfile.getSize());
// Returns the uncompressed size of the entry data, or -1 if not known.
System.out.println("Time" + zipfile.getTime());
// Returns the modification time of the entry, or -1 if not specified.
System.out.println("Dir" + zipfile.isDirectory());
// Returns true if this is a directory entry.
if(! zipfile.isDirectory()){
String dirname = zipfile.getName();
dirname =
dirname.replace('/',System.getProperties().getProperty("file.separator",
null).charAt(0));
File directorio = new File(dirname);
System.out.println("Fin " + directorio.getParent());
dirname = directorio.getParent();
if (dirname != null)
{
directorio = new File(dirname);
if(! directorio.mkdirs())
System.out.println("Errores" + dirname);
}
InputStream fin = zip.getInputStream(zipfile);
FileOutputStream fous = new
FileOutputStream(zipfile.getName());
byte b;
while (fin.available() != 0){
b = (byte) fin.read();
fous.write( b);
};
fin.close();
}else{
String dirname = zipfile.getName();
dirname = dirname.substring(0,dirname.length()-1);
dirname =
dirname.replace('/',System.getProperties().getProperty("file.separator",
null).charAt(0));
File directorio = new File(dirname);
if(! directorio.mkdirs())
System.out.println("Errores" + dirname);
}
}
zip.close();
// fous.close();
}catch (Exception e){
System.err.println("Caught exception " + e.toString());
}
}
}
--
--------------------------------------------------
Juan Pedro Barbancho Manch๏ฟฝn
CTI UCO
http://www.uco.es/grupos/cti
ct2bamaj@uco.es
Java Senior Programmer
Search for a job
Technical Details
Message-ID:
<34D60825.D62C14EB@uco.es>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII X-Google-Thread: 1116f3,544f77e9e3dc02b5,start X-Google-Attributes: gid1116f3,public From: Juan Pedro Barbancho Manchon <ct2bamaj@uco.es> Subject: Junzip Date: 1998/02/02 Message-ID: <34D60825.D62C14EB@uco.es> X-Deja-AN: 321461036 Content-Transfer-Encoding: 8bit X-Priority: 3 (Normal) Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Organization: CTI Newsgroups: es.comp.lenguajes.java