Results 1 to 4 of 4

Thread: UnZip

  1. #1
    hello_swe is offline Member
    Join Date
    Feb 2008
    Posts
    3
    Rep Power
    0

    Default UnZip

    i need help with this code:
    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();
    		}
    	}
    }
    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.

  2. #2
    gibsonrocker800's Avatar
    gibsonrocker800 is offline Senior Member
    Join Date
    Nov 2007
    Location
    New York
    Posts
    143
    Rep Power
    0

    Default

    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.

  3. #3
    hello_swe is offline Member
    Join Date
    Feb 2008
    Posts
    3
    Rep Power
    0

    Default

    yes, i does exist. but same problem. even with different .zip file.

  4. #4
    hello_swe is offline Member
    Join Date
    Feb 2008
    Posts
    3
    Rep Power
    0

    Default

    i modified the code but it is behaving very strange:

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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •