Results 1 to 4 of 4
Thread: UnZip
- 02-16-2008, 10:12 PM #1
Member
- Join Date
- Feb 2008
- Posts
- 3
- Rep Power
- 0
UnZip
i need help with this code:
output:::Java Code:package taskUnZip; import java.io.*; import java.util.*; import java.util.zip.*; public class UnZip { static final int BUFFER = 2048; public static void main(String argv[]) { try { BufferedOutputStream dest = null; BufferedInputStream is = null; ZipEntry entry; ZipFile zipfile = new ZipFile("D:\\Game.zip"); Enumeration e = zipfile.entries(); while (e.hasMoreElements()) { entry = (ZipEntry) e.nextElement(); System.out.println("Extracting: " + entry); is = new BufferedInputStream(zipfile.getInputStream(entry)); int count; byte data[] = new byte[BUFFER]; FileOutputStream fos = new FileOutputStream(entry.getName()); dest = new BufferedOutputStream(fos, BUFFER); while ((count = is.read(data, 0, BUFFER)) != -1) { dest.write(data, 0, count); } dest.flush(); dest.close(); is.close(); } } catch (Exception e) { e.printStackTrace(); } } }
Extracting: Game/Instructions.txt
java.io.FileNotFoundException: Game\Instructions.txt (The system cannot find the path specified)
at java.io.FileOutputStream.open(Native Method)
at java.io.FileOutputStream.<init>(Unknown Source)
at java.io.FileOutputStream.<init>(Unknown Source)
at taskUnZip.UnZip.main(UnZip.java:25)
any idea what is going wrong here.
- 02-17-2008, 05:20 AM #2
I didn't read your code, but according to the error, it can't find the file Instructions.txt ... so make sure Instructions.txt exists, and is within the same folder as this program, or you could just specify the file path of Instructions.txt ... I might be wrong though.
- 02-17-2008, 11:31 AM #3
Member
- Join Date
- Feb 2008
- Posts
- 3
- Rep Power
- 0
yes, i does exist. but same problem. even with different .zip file.
- 02-17-2008, 10:58 PM #4
Member
- Join Date
- Feb 2008
- Posts
- 3
- Rep Power
- 0
i modified the code but it is behaving very strange:
Exception is:Java Code:package taskUnZip; import java.io.*; import java.util.zip.*; public class UnZip { public static void main(String argv[]) { try { File f = new File("D:\\billing_zip"); ZipFile zf = new ZipFile("D:\\billing_zip.zip"); ZipInputStream zis = new ZipInputStream(new FileInputStream(f)); unZip1(f, zf, zis); } catch (Exception e) { e.printStackTrace(); } } private static void unZip1(File dirDestiny, ZipFile zipFile, ZipInputStream zis) throws IOException { final int BUFFER = 2048; //byte data[] = new byte[BUFFER]; ZipEntry zipEntry = zis.getNextEntry(); while (zipEntry != null) { File file = new File(dirDestiny.getAbsolutePath() + File.separator + zipEntry.getName()); if (zipEntry.isDirectory()) { file.mkdirs(); } else { BufferedInputStream bis = new BufferedInputStream(zipFile .getInputStream(zipEntry), BUFFER); String parentName; if ((parentName = file.getParent()) != null) { File dir = new File(parentName); dir.mkdirs(); } BufferedOutputStream bos = new BufferedOutputStream( new FileOutputStream(file), BUFFER); int count; while ((count = bis.read()) != -1) { bos.write(count); } bis.close(); bos.close(); } zipEntry = zis.getNextEntry(); } } }
java.io.FileNotFoundException: D:\billing_zip (Access is denied)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(Unknown Source)
at taskUnZip.UnZip.main(UnZip.java:12)
a strange thing is: it is changing the property of the billing_zip into readonly.
Any suggestions:confused:


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks