0

我试图简单地阅读下面的文件src/assets/data(我已经创建了data包含一些文本文件的目录)。

我尝试了很多方法都没有成功:

this.file.resolveDirectoryUrl("/assets/data") // as well tested with "/www/assets/data" and "/www/assets/data/", with or without the front "/", as well with all those solutions with `this.file.applicationDirectory +` in front of the string
  .then(directoryEntry => {
    directoryEntry.createReader().readEntries(function (entries: Entry[]) {
      for (let entry of entries) {
        console.log(entry);
      }
    })
  });

this.file.resolveLocalFilesystemUrl(this.file.applicationDirectory+"assets/data/")

以及建议另一个答复的内容

(<any>window).resolveLocalFileSystemURL(this.file.applicationDirectory + "www/assets/data/",
  function (fileSystem) {
    fileSystem.createReader().readEntries(function (entries: Entry[]) {
      for (let entry of entries) {
        console.log(entry);
      }
    })
  },
  function (error) {
    console.error(error);
  }
);

对于所有这些解决方案,我总是以以下错误结束:“ A URI supplied to the API was malformed, or the resulting Data URL has exceeded the URL length limitations for Data URLs.

我正在运行科尔多瓦ionic cordova run browser --port=8000并且this.file.applicationDirectory等于http://localhost:8000/

有人知道如何做这个简单的事情吗?或者我应该将我的data文件夹移动到另一个地方并使用另一个 API 来简单地读取我的本地应用程序文件?

我在我的中使用以下依赖项版本(以及其他版本)package.json

"@angular/core": "5.0.3",
"@ionic-native/core": "4.4.0",
"@ionic-native/file": "^4.5.3",
"cordova-plugin-file": "^6.0.1",
"cordova-plugin-ionic": "3.0.0",
"cordova-browser": "~5.0.3"
4

1 回答 1

0

applicationDirectory浏览器平台不支持,所以它不会在那里工作,你必须在支持的平台之一中进行测试。(iOS、安卓、Windows、OSX)

于 2018-02-05T10:36:40.803 回答