Java Forums

Main Menu
Home
Today's Posts
FAQ
Search
Contact Us

Java Network
Linux Archive
Java Tips
Java Tips Blog

Sponsored Links





Welcome to the Java Forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community, you will:

  • have access to post topics
  • communicate privately with other members (PM)
  • not see advertisements between posts
  • have the possibility to earn one of our surprises if you are an active member
  • access many other special features that will be introduced later.

Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact us.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 02-17-2008, 12:12 AM
Member
 
Join Date: Feb 2008
Posts: 3
hello_swe is on a distinguished road
UnZip
i need help with this code:
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(); } } }
output:::
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.
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 02-17-2008, 07:20 AM
gibsonrocker800's Avatar
Senior Member
 
Join Date: Nov 2007
Location: New York
Posts: 143
gibsonrocker800 is on a distinguished road
Send a message via AIM to gibsonrocker800
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.
__________________
//Haha javac, can't see me now, can ya?
Bookmark Post in Technorati
Reply With Quote
  #3 (permalink)  
Old 02-17-2008, 01:31 PM
Member
 
Join Date: Feb 2008
Posts: 3
hello_swe is on a distinguished road
yes, i does exist. but same problem. even with different .zip file.
Bookmark Post in Technorati
Reply With Quote
  #4 (permalink)  
Old 02-18-2008, 12:58 AM
Member
 
Join Date: Feb 2008
Posts: 3
hello_swe is on a distinguished road
i modified the code but it is behaving very strange:

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(); } } }
Exception is:

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
Bookmark Post in Technorati
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +3. The time now is 08:19 AM.


VBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org