title: HTML5 and Javascript : Opening and Reading a Local File with File API
body: <p>I am using Google Web Toolkit for a project and would like the user to select a text file to open in a text window inside the browser.  Here's the almost working code:</p>
  
  <pre><code> private DialogBox createUploadBox() {
       final DialogBox uploadBox = new DialogBox();
       VerticalPanel vpanel = new VerticalPanel();
       String title = "Select a .gms file to open:";
       final FileUpload upload = new FileUpload();
       uploadBox.setText(title);
       uploadBox.setWidget(vpanel);
       HorizontalPanel buttons = new HorizontalPanel();
       HorizontalPanel errorPane = new HorizontalPanel();
       Button openButton = new Button( "Open", new ClickHandler() {
          @Override
          public void onClick(ClickEvent event) {
              String filename = upload.getFilename();
              int len = filename.length();
              if (len &lt; 5) {
                  Window.alert("Please enter a valid filename.\n\tFormat: &lt;filename&gt;.gms");
              } else if (!filename.substring(len-4).toLowerCase().equals(".gms")) {
                  Window.alert(filename.substring(len-4) + " is not valid.\n\tOnly files of type .gms are allowed.");
              } else {
                  Window.alert(getFileText(filename));
              }
          }
          private native String getFileText(String filename) /*-{
              // Check for the various File API support.
              if (window.File &amp;&amp; window.FileReader &amp;&amp; window.FileList &amp;&amp; window.Blob) {
                  // Great success! All the File APIs are supported.
                  var reader = new FileReader();
                  var file = File(filename);
                  str = reader.readAsText(file);
                  return str;
              } else {
                  alert('The File APIs are not fully supported in this browser.');
                  return;
              }
          }-*/;
       });
       Button cancelButton = new Button( "Cancel", 
               new ClickHandler() {
          @Override
          public void onClick(ClickEvent event) {
              uploadBox.hide();               
          }
       });
       buttons.add(openButton);
       buttons.add(cancelButton);
       vpanel.add(upload);
       vpanel.add(buttons);
       vpanel.add(errorPane);
       uploadBox.setAnimationEnabled(true);
       uploadBox.setGlassEnabled(true);
       uploadBox.center();
       return uploadBox;
   }
  </code></pre>
  
  <p>Whenever I try to actually use this function in my program, I get:</p>
  
  <p><strong>(NS_ERROR_DOM_SECURITY_ERR): Security error</strong></p>
  
  <p>I'm certain it is being cased by: </p>
  
  <pre><code>var file = new File(filename, null);
  </code></pre>
  
  <p>Disclaimer: I'm not a Javascript programmer by any stretch, please feel free to point out any obvious mistakes I'm making here.</p>