wood burning stoves 2.0*
The moose likes Java in General and the fly likes Exception in thread Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Exception in thread "main" java.io.FileNotFoundException: ReadZip (Access is denied)" Watch "Exception in thread "main" java.io.FileNotFoundException: ReadZip (Access is denied)" New topic
Author

Exception in thread "main" java.io.FileNotFoundException: ReadZip (Access is denied)

Raaja Gotluru
Ranch Hand

Joined: Mar 02, 2010
Posts: 108
Hi,

I am using the following program to unzip a zip file containing xml files

ZipFile zf = new ZipFile("c:\\ReadZip.zip");
Enumeration e = zf.entries();
while (e.hasMoreElements()) {
ZipEntry ze = (ZipEntry) e.nextElement();
System.out.println("Unzipping " + ze.getName());
FileOutputStream fout = new FileOutputStream(ze.getName());
InputStream in = zf.getInputStream(ze);
for (int c = in.read(); c != -1; c = in.read()) {
fout.write(c);
}
in.close();
fout.close();
}
but I am getting the exception as Exception in thread "main" java.io.FileNotFoundException: ReadZip (Access is denied).

I tried this way also:

String destinationname = "c:\\testZip";
byte[] buf = new byte[1024];
ZipInputStream zipinputstream = null;
ZipEntry zipentry;
zipinputstream = new ZipInputStream(new FileInputStream("c:\\ReadZip.zip"));
zipentry = zipinputstream.getNextEntry();
while (zipentry != null) {
String entryName = zipentry.getName();
FileOutputStream fileoutputstream;
File newFile = new File(entryName);
String directory = newFile.getParent();

if (directory == null) {
if (newFile.isDirectory())
break;
}
fileoutputstream = new FileOutputStream(destinationname + entryName);
int n;
while ((n = zipinputstream.read(buf, 0, 1024)) > -1){
fileoutputstream.write(buf, 0, n);
}
fileoutputstream.close();
zipinputstream.closeEntry();
zipentry = zipinputstream.getNextEntry();
}
zipinputstream.close();

but I am getting the exception as <terminated> ExtractFiles [JavaApplication] c:\Program Files\java\jre6\bin\javaw.exe.

Where I am going wrong. Please guide me.

Thanking you.
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14074
    
  16

Well, the exception message quite clearly says what the problem is: FileNotFoundException and Access denied.

Make sure that the file that you are trying to open actually exists: c:\ReadZip.zip
Also, make sure that you are allowed to read it.

Which version of Windows are you using? On some versions, certain directories such as the root directory C:\ are protected, so that normal programs can't read or write files from or to there (for good reasons!). Try putting the file in some other directory, where you are allowed to read and write files.


Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
Bijesh Roy
Greenhorn

Joined: Jun 28, 2011
Posts: 8
The file c:\ReadZip.zip or the whole directory don't have any read permission so you are getting this error. Change the permission it will work...
Raaja Gotluru
Ranch Hand

Joined: Mar 02, 2010
Posts: 108
Hi,

Thanks for the reply.

The file exists in the C drive and I am using windows xp. Even after changing the drive and folder also I am getting the same exception. I am able to extract that zip file using winzip and winrar tools. so I dont think there will be a permission problem.

--Raaja

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Exception in thread "main" java.io.FileNotFoundException: ReadZip (Access is denied)
 
Similar Threads
Character Encoding
Extracting Image From A Jar File
Problem with searching for a file which is in the zip file
Extract .Z files
Java --- ZIP & UNZIP