title: How to write to a file in applets in java?
body: <p>Since Applets run in sandbox mode in browsers, I am using AccessController.doPrivileged to write to a file. It writes to the file when I run it in Eclipse, but doesn't write when I access the applet in browser.
  What am I missing? Here is the code:</p>
  
  <pre><code>public class HelloWorld extends Applet {
  
      public void paint(Graphics g) {
          AccessController.doPrivileged(new PrivilegedAction&lt;Boolean&gt;() {
              public Boolean run() {
                  try {
                      System.out.println(System.getProperty("user.home"));
                      String userHome = System.getProperty("user.home");
                      FileWriter fw = new FileWriter(userHome + File.separator
                              + "test" + File.separator + "area.txt");
                      fw.write("The area is 20m");
                      fw.flush();
                      fw.close();
  
                  } catch (IOException ioe) {
                      System.err.println(ioe);
                  }
                  return Boolean.TRUE;
              }
          });
      }
  }
  </code></pre>