This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
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

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Exception in thread "main" ReadZip (Access is denied)" Watch "Exception in thread "main" ReadZip (Access is denied)" New topic

Exception in thread "main" ReadZip (Access is denied)

Raaja Gotluru
Ranch Hand

Joined: Mar 02, 2010
Posts: 118

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

ZipFile zf = new ZipFile("c:\\");
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 =; c != -1; c = {
but I am getting the exception as Exception in thread "main" 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:\\"));
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())
fileoutputstream = new FileOutputStream(destinationname + entryName);
int n;
while ((n =, 0, 1024)) > -1){
fileoutputstream.write(buf, 0, n);
zipentry = zipinputstream.getNextEntry();

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: 15101

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:\
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 8 API documentation
Bijesh Roy

Joined: Jun 28, 2011
Posts: 14
The file c:\ 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: 118

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.


I agree. Here's the link:
subject: Exception in thread "main" ReadZip (Access is denied)
It's not a secret anymore!