title: Read write file from Javascript in Xcode project
body: <p>I am making a iPhone app using JavaScript. I want to open a file as a result file and I need to write some result logs and data from javascript. With the iphone I use to use documentsDirectory to open file and do read/write operations. But now I want to do this in javascript. Now how can I use this documentsDirectory to write a file and access it later from Xcode. 
  Any suggestions?</p>
  
  <p>Thanks
  Akansha</p>
  
  <p>I am using following youtube api code. I have made a file called youtubeAPI.html and calling this file from objective-c code. It opens the page successfully. Now I want to open a file and write the something everytime it changes it states, and then need to to show that file in the final result from obejective-c. Please tell me how can i do this.</p>
  
  <pre><code>&lt;!DOCTYPE HTML&gt;
  &lt;html&gt;
  &lt;body&gt;
  &lt;div id="player"&gt;&lt;/div&gt;
  &lt;script&gt;
      //Load player api asynchronously.
      var tag = document.createElement('script');
      tag.src = "http://www.youtube.com/player_api";
      var firstScriptTag = document.getElementsByTagName('script')[0];
      firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
      var done = false;
      var player;
      function onYouTubePlayerAPIReady() {
          player = new YT.Player('player', {
            height: '390',
            width: '640',
            videoId: 'JW5meKfy3fY',
            events: {
              'onReady': onPlayerReady,
              'onStateChange': onPlayerStateChange
            }
          });
      }
      function onPlayerReady(evt) {
          evt.target.playVideo();
      }
      function onPlayerStateChange(evt) {
          if (evt.data == YT.PlayerState.PLAYING &amp;&amp; !done) { // NEED TO ADD FILE OPERATION HERE
              setTimeout(stopVideo, 6000);
              done = true;
          }
      }
      function stopVideo() {
          player.stopVideo();
      }
  &lt;/script&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>