科尔多瓦文件插件 - 阅读从www文件夹? [英] Cordova File Plugin - Read from www folder?

查看:221
本文介绍了科尔多瓦文件插件 - 阅读从www文件夹?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在哪里,我想用科尔多瓦文件API来读取/ www文件夹的文件在Android上的问题(其他平台未测试)。有冲突的部分信息有关这是否是可能的,或者不在互联网上。我跟着像一个例子:

I'm having an issue on Android (not tested on other platforms) where I would like to use the cordova file API to read a file from the /www folder. There are conflicting pieces of information on the internet about whether this is possible or not. I've followed an example like:

window.resolveLocalFileSystemURL(cordova.file.applicationDirectory +WWW / index.html的,gotFile,失败);

但是我得到错误1(找不到文件)。我可以使用AJAX来获取我需要的文件,但它不适合我的用例。我想查询在/ www文件夹目录和读取动态命名的文件。任何想法?

However I'm getting error 1 (file not found). I can use AJAX to retrieve the file I need but it doesn't suit my use case. I want to query a directory in the /www folder and read a dynamically named file. Any ideas?

我想有一个更新的答案,因为我见过的一个是1岁以上:
<一href=\"http://stackoverflow.com/questions/15100260/can-you-read-files-in-the-www-folder-using-phonegap-s-js-methods\">Can您使用PhoneGap的。的JS方法www文件夹中读取文件?

I'd like to have an updated answer, as the one I've seen is over 1 year old: Can you read files in the www folder using PhoneGap.'s JS methods?

先谢谢了。

推荐答案

您可以使用此函数获取WWW所有可用的文件/文件夹

You can use this function to get all available files in www/ folder

function listDir(path){
  window.resolveLocalFileSystemURL(path,
    function (fileSystem) {
      var reader = fileSystem.createReader();
      reader.readEntries(
        function (entries) {
          console.log(entries);
        },
        function (err) {
          console.log(err);
        }
      );
    }, function (err) {
      console.log(err);
    }
  );
}
//example: list of www/ folder in cordova/ionic app.
listDir(cordova.file.applicationDirectory + "www/");

(www文件夹是只读模式,您不能在写什么。的科尔多瓦插件文件文档解释这个问题。但是你可以使用的将copyTo()API HTML5文件的方法将数据复制到其他位置)

(The www folder is in readonly mode. You can't write anything in it. Cordova plugin file documentation explain this. But you can use the copyTo() method of html5 API File to copy your data in another location)

这篇关于科尔多瓦文件插件 - 阅读从www文件夹?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆