Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Raaja Gotluru
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 15207
36
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Bijesh Roy
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic