title: IOException - Access Denied Using FileOutputStream
body: <p>I get the following IOException :</p>
  
  <pre><code>java.io.IOException: Access is denied
   at java.io.WinNTFileSystem.createFileExclusively(Native Method)
   at java.io.File.createNewFile(File.java:850)
   at zipUnzipper.main(zipUnzipper.java:41)
  </code></pre>
  
  <p>When trying to run the following piece of code :</p>
  
  <pre><code>public class zipUnzipper {
      public zipUnzipper() {
      }
  
      public static void main(String[] args){
  
          //Unzip to temp folder. Add all files to mFiles. Print names of all files in mFfiles.
          File file = new File("C:\\aZipFile.zip");
          String  filename = file.getName();
          String filePathName = new String();
  
          int o = filename.lastIndexOf('.');
              filename = filename.substring(0,o);
  
          try {      
                  ZipFile zipFile = new ZipFile (file.getAbsoluteFile());
                  Enumeration entries = zipFile.entries();
                  while(entries.hasMoreElements()) {
                      ZipEntry zipEntry = (ZipEntry) entries.nextElement();
                      System.out.println("Unzipping: " + zipEntry.getName());
                      BufferedInputStream bis = new BufferedInputStream(zipFile.getInputStream(zipEntry));
                      byte[] buffer = new byte[2048];
                      filePathName = "C:\\TEMP\\"+filename+"\\";
                      File fileToWrite = new File(filePathName+ zipEntry.getName());
                      fileToWrite.mkdirs();
                      fileToWrite.createNewFile();
                      FileOutputStream fos = new FileOutputStream(fileToWrite);
                      BufferedOutputStream bos = new BufferedOutputStream( fos , buffer.length );
                      int size;
                      while ((size = bis.read(buffer, 0, buffer.length)) != -1) {
                          bos.write(buffer, 0, size);
                      }
                      bos.flush();
                      bos.close();
                      bis.close();
                  }
                  zipFile.close();
                  File folder = new File (filePathName);
                  File [] mFiles = folder.listFiles();
  
                  for (int x=0; x&lt;mFiles.length; x++) {
                                  System.out.println(mFiles[x].getAbsolutePath());
                          }
          } catch (ZipException ze) {
              ze.printStackTrace();
          } catch (IOException ioe) {
              ioe.printStackTrace();
          }
  
      }
  }
  </code></pre>
  
  <p>It seems to me that for some reason the JVM can't create a new file. The code runs perfectly well if the files already exist. Is there some kind of access file which dictates whether the JVM can create a new file or am I simply doing something wrong?</p>
  
  <p>Any help is much appreciated :-)</p>
  
  <p>I'm running Java 1.4 and have been testing in JDeveloper in Windows XP.</p>