title: Java application cannot write/read serialization file when installed to C:/Program Files - java.io.FileNotFoundException: (Access is denied)
body: <p>My app uses this code to persistently save an ArrayList so it can be recalled when the app is restarted.</p>
  
  <pre><code>    private static void storeDevices() {
      // Object serialization
      try {
          FileOutputStream fos = new FileOutputStream("devices.ser");
          ObjectOutputStream oos = new ObjectOutputStream(fos);
          oos.writeObject(devices);
          oos.flush();
          oos.close();
      }
      catch(Exception e) {
          showAlert("Store Devices", "Exception storing devices to file: " + e);
      } 
  }
  </code></pre>
  
  <p>Everything works fine when I run from Netbeans. I have wrapped the app in an installer (using Launch4J and Inno Setup Compiler) and when I install the app to C:/Program Files/MyApp (on Windows 7) the above code gives the following exception:</p>
  
  <blockquote>
    <p>Exception storing devices to file: java.io.FileNotFoundException: devices.ser (Access is denied)</p>
  </blockquote>
  
  <p>However, when I install to C:/MyApp, everything works fine.</p>
  
  <p>Is this something to do with read/write permission being inherited from the C:/Program Files directory? I know I may be able to solve this be creating the file in C:/temp directory or somewhere like that but I don't want to have to resort to that. So is there any way I can write/read files in my C:/Program Files/MyApp directory?</p>