is an exception message thrown? is there no zip file created?
how do you know there is a fault?
stultuske
Posting Sensei
3,137 posts since Jan 2007
Reputation Points: 1,114
Solved Threads: 433
On line 8 did you put the name of a real zip file?
JamesCherrill
Posting Genius
6,373 posts since Apr 2008
Reputation Points: 2,130
Solved Threads: 1,073
of course yes :)
I think i found the problem:
FileOutputStream fos = new
FileOutputStream(entry.getName());
this extratcs all the data to your jars current directory??? try this:
FileOutputStream fos = new
FileOutputStream("c:\\"+entry.getName());
btw your buffer should be static, and your missing ';' after zip name:
final int BUFFER....//change to static
String fileName = "...." //put a semicolon at the end
DavidKroukamp
Practically a Master Poster
693 posts since Dec 2011
Reputation Points: 282
Solved Threads: 169
I'm try it now but there is nothing change
I dont understand?
DavidKroukamp
Practically a Master Poster
693 posts since Dec 2011
Reputation Points: 282
Solved Threads: 169
Presumably, if System.out.println("Extracting: " +entry); isn't outputting anything, AND there isn't a java.io.FileNotFoundException then the input file has been found, but it doesn't contain any zipped content?
JamesCherrill
Posting Genius
6,373 posts since Apr 2008
Reputation Points: 2,130
Solved Threads: 1,073
Here's a really dumb question... is it possible that the code your are executing isn't what you think - eg out-of-date .class files hanging around etc? Maybe a quick print at the start and end of execution would give positive confirmation?
JamesCherrill
Posting Genius
6,373 posts since Apr 2008
Reputation Points: 2,130
Solved Threads: 1,073
Presumably, if System.out.println("Extracting: " +entry); isn't outputting anything, AND there isn't a java.io.FileNotFoundException then the input file has been found, but it doesn't contain any zipped content?
Maybe what JamesCherrill is right.. Go to your c drive, create two text files with anynames and any random data... next select both textfiles, right click and send to Compressed zip file... next name that compressed zip file test.zip and make sure it resides in your c:\\test.zip... now try running this and seeing what happens...(delete the files after you zipped them or you might get confused as to whether they were extracted or the originals) now try here:
import java.io.*;
import java.util.zip.*;
public class Unzip {
static final int BUFFER = 2048;
public static void main(String[] args) {
try {
String fileName = "c:\\test.zip"; //but your zip file
String unzipToFolder = "c:\\";
BufferedOutputStream dest = null;
FileInputStream fis = new FileInputStream(fileName);
ZipInputStream zis = new ZipInputStream(new BufferedInputStream(fis));
ZipEntry entry;
while ((entry = zis.getNextEntry()) != null) {
System.out.println("Extracting: " + entry);
int count;
byte data[] = new byte[BUFFER];
// write the files to the disk
FileOutputStream fos = new FileOutputStream(unzipToFolder + entry.getName());
dest = new BufferedOutputStream(fos, BUFFER);
while ((count = zis.read(data, 0, BUFFER))
!= -1) {
dest.write(data, 0, count);
}
dest.flush();
dest.close();
}
zis.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
[edit]obviously i dont get the same results or else i wouldnt have said i found the problem...And yes this code is tested and works
DavidKroukamp
Practically a Master Poster
693 posts since Dec 2011
Reputation Points: 282
Solved Threads: 169
I edited that down to the essential code to see into the zip file, and used a file input dialog to ensure the zip file path was correct. This code works for me - maybe you can try it with your zip file?
void doZip() {
try {
JFileChooser fileChooser = new JFileChooser();
fileChooser.showOpenDialog(null);
File chosen = fileChooser.getSelectedFile();
FileInputStream fis = new FileInputStream(chosen);
ZipInputStream zis = new ZipInputStream(new BufferedInputStream(fis));
ZipEntry entry;
while ((entry = zis.getNextEntry()) != null) {
System.out.println("Found: " + entry);
}
zis.close();
} catch (Exception e) {
e.printStackTrace();
}
}
JamesCherrill
Posting Genius
6,373 posts since Apr 2008
Reputation Points: 2,130
Solved Threads: 1,073