title: read a text file from sdcard and display using phone gap
body: <p>I have example.txt file sdcard and I want to display it using phone gap.I am very new to android and phone gap please help.
  Here is my example.txt file:</p>
  
  <pre><code>     &lt;h2&gt;This file is in sdcard&lt;/h2&gt;
  </code></pre>
  
  <p>Here is my phonegap.java</p>
  
  <pre><code>    package com.example.phonegap;
      import org.apache.cordova.DroidGap;
  
       public class Phonegap extends DroidGap{
          /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          super.loadUrl("file:///android_asset/www/myfile.html");
         }
  
      }
  </code></pre>
  
  <p>and here is the myfile.html in www:</p>
  
  <pre><code>       &lt;!DOCTYPE html&gt;
       &lt;html&gt;
       &lt;head&gt;
        &lt;title&gt;FileReader Example&lt;/title&gt;
  
      &lt;script type="text/javascript" charset="utf-8" src="cordova-1.5.0.js"&gt;&lt;/script&gt;
      &lt;script type="text/javascript" charset="utf-8"&gt;
  
      // Wait for PhoneGap to load
      //
      function onLoad() {
          document.addEventListener("deviceready", onDeviceReady, false);
      }
  
      // PhoneGap is ready
      //
      function onDeviceReady() {
          window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail);
      }
  
      function gotFS(fileSystem) {
          fileSystem.root.getFile("file:///sdcard/example.txt", {create: true}, gotFileEntry, fail);
      }
  
      function gotFileEntry(fileEntry) {
          fileEntry.file(gotFile, fail);
      }
  
      function gotFile(file){
          readDataUrl(file);
          readAsText(file);
      }
  
      function readDataUrl(file) {
          var reader = new FileReader();
          reader.onloadend = function(evt) {
              console.log("Read as data URL");
              console.log(evt.target.result);
          };
          reader.readAsDataURL(file);
      }
  
      function readAsText(file) {
          var reader = new FileReader();
          reader.onloadend = function(evt) {
              console.log("Read as text");
              console.log(evt.target.result);
          };
          reader.readAsText(file);
      }
  
      function fail(evt) {
          console.log(evt.target.error.code);
      }
  
      &lt;/script&gt;
    &lt;/head&gt;
    &lt;body&gt;
      &lt;h1&gt;Example&lt;/h1&gt;
      &lt;p&gt;Read File&lt;/p&gt;
    &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>