0
votes

"readme.txt" not found. Phonegap example are not working on iphone and android


              document.addEventListener("deviceready", onDeviceReady, false);

          function onDeviceReady() {
              window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail);
          }
          function gotFS(fileSystem) {
              fileSystem.root.getFile("readme.txt", null, gotFileEntry, fail);
          }

          function gotFileEntry(fileEntry) {
              console.log(evt.target.error.code);

          }


          function fail(evt) {

              console.log(evt.target.error.code);
          }

1
When we add any file in www folder it become the part on pacakge and we can not extract path from package. Instead we can use relative path and read the file. (if not found then create it)Neel Kamal

1 Answers

0
votes

You can only get file in the Document folder of the application.

If the file is not found you can create it by replacing 'null' with {create: true} in the getFile() function like so

    <script type="text/javascript" charset="utf-8">
        document.addEventListener("deviceready", onDeviceReady, false);

        function onDeviceReady() {
            window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, gotFS, fail);
        }

        function gotFS(fileSystem) {
            fileSystem.root.getFile("readme.txt", {create: true}, gotFileEntry, fail);
        }

        function gotFileEntry(fileEntry) {
            console.log("gotFileEntry");
        }

        function fail(evt) {
            console.log("Error : "+evt.code);
        }
    </script>