ho bisogno di un aiuto la seguente classe esegue zip e unzip
ma devo poter cercare un file in una directory del mio disco e lo stesso per unzippare.
GRazie
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.OutputStream;
import java.util.Enumeration;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import java.util.zip.ZipInputStream;
import java.util.zip.ZipOutputStream;
import java.io.File;
import java.io.FileOutputStream;
/**
* @author Admin
*
* To change the template for this generated type comment go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
public class compressore {
public File comprimi (String[] _filenames) {
// These are the files to include in the ZIP file
// Create a buffer for reading the files
byte[] buf = new byte[1024];
File outfile = null;
try {
// Create the ZIP file
String outFilename = "outfile.zip";
ZipOutputStream out = new ZipOutputStream(new FileOutputStream(outFilename));
outfile = new File(outFilename);
// Compress the files
for (int i=0; i<_filenames.length; i++) {
FileInputStream in = new FileInputStream(_filenames[i]);
// Add ZIP entry to output stream.
out.putNextEntry(new ZipEntry(_filenames[i]));
// Transfer bytes from the file to the ZIP file
int len;
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
// Complete the entry
out.closeEntry();
in.close();
}
// Complete the ZIP file
out.close();
}catch (FileNotFoundException fnf) {
}
catch (IOException e) {
}
return outfile;
}
public void elenca (String _filename){
try {
// Open the ZIP file
ZipFile zf = new ZipFile(_filename);
// Enumerate each entry
for (Enumeration entries = zf.entries(); entries.hasMoreElements(){
// Get the entry name
String zipEntryName = ((ZipEntry)entries.nextElement()).getName();
}
}
catch (FileNotFoundException fnf) {
}catch (IOException e) {
}
}
public void decomprimi (String _filename)
{
try {
// Open the ZIP file
String inFilename = _filename;
ZipInputStream in = new ZipInputStream(new FileInputStream(inFilename));
// Get the first entry
ZipEntry entry = in.getNextEntry();
// Open the output file
String outFilename = "o";
OutputStream out = new FileOutputStream(outFilename);
// Transfer bytes from the ZIP file to the output file
byte[] buf = new byte[1024];
int len;
while ((len = in.read(buf)) > 0) {
out.write(buf, 0, len);
}
// Close the streams
out.close();
in.close();
}
catch (FileNotFoundException fnf) {
}
catch (IOException e) {
}
}
}