title: Phonegap Android create file if not exists and write to it
body: <p>Morning,</p>
  
  <p>I am using the following to create a file on the local file system. This creates a file if it did not already exist.</p>
  
  <pre><code>function onDeviceReady() {
      window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail);
  
  }
  
  function gotFS(fileSystem) {
          fileSystem.root.getFile("test.txt", {create: true}, gotFileEntry, fail);
      }
  
      function gotFileEntry(fileEntry) {
          fileEntry.createWriter(gotFileWriter, fail);
      }
  
      function gotFileWriter(writer) {
          writer.onwrite = function(evt) {
              alert("write success");
          };
          writer.write("We are testing")
  
      }
  
      function fail(error) {
          if(error.code == 1){
              alert('not found');
          }
          alert(error.code);
      }
  </code></pre>
  
  <p>However, I need to write to the file ONLY if it did not already exist.
  I tried using </p>
  
  <pre><code>function gotFS(fileSystem) {
              fileSystem.root.getFile("test.txt", null, gotFileEntry, fail);
          }
  
  function gotFS2(fileSystem) {
  alert('trying again');
              fileSystem.root.getFile("test.txt", {create:true}, gotFileEntry, fail);
          }
  
  function fail(error) {
  
              if(error.code == 1){
                  alert('not found');
                  gotFS2(fileSystem);
              }
              alert(error.code);
          }
  </code></pre>
  
  <p>and then calling gotFS2 if error.code == 1
  but that did nothing - it didn't even create the file when it didn't exist.</p>
  
  <p>It seems that gotFS2 was not called, yet <code>alert('not found');</code> in the  function fail(error)  works.</p>
  
  <p>What's the easiest way to do what I am trying to do?</p>