开发者

Local File path not found Phonegap

开发者 https://www.devze.com 2023-03-30 22:42 出处:网络
\"readme.txt\" not found. Phonegap example are not working on iphone and android document.addEventListener(\"deviceready\", onDeviceReady, false);

"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 gotF开发者_如何学编程S(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);
          }


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>
0

精彩评论

暂无评论...
验证码 换一张
取 消