从 assets/www 目录访问文件 [英] access files from assets/www directory

查看:21
本文介绍了从 assets/www 目录访问文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个名为 foo.html 的文件(相当舒服)在我的 assets/www 目录(在我的 index.html 旁边).

let's say I've got a file called foo.html sitting (quite comfortable) in my assets/www directory (next to my index.html).

我想将该文件复制到设备上的另一个位置.我的第一种方法 window.resolveLocalFileSystemURI("foo.html", cool(), notCool()); 不起作用.也没有像 www/这样的前缀.

I'd like to copy that file to another location on the device. My first approach window.resolveLocalFileSystemURI("foo.html", cool(), notCool());is not working. Also with a prefix like www/ it won't.

知道是否真的可以通过 Phonegap 访问文件会很有趣.我不相信,因此希望看到如何获取资产目录中文件的 FileEntry 的代码片段 - 如果可能的话.

It would be interesting to know if it is actually possible at all to access files via Phonegap. I'm not convinced and therefore would like to see a code snippet how to obtain a FileEntry for files in the assets directory - if possible.

好的,现在我们接到了这样的电话

edit: Ok now we've got a call like this

window.resolveLocalFileSystemURI("file:///android_asset",
  function(entry){
    console.log(entry.fullPath);},
  function(evt){
    console.log(evt.code);}
);

但是我们在 code: undefined (Phonegap v1.2) 和 code: 1 和 v1.0(代码 1 = 文件未找到?!)

but we've get an error with code: undefined (Phonegap v1.2) and code: 1 with v1.0 (code 1 = file not found?!)

推荐答案

你应该可以这样访问文件:

You should be able to access the file this way:

window.resolveLocalFileSystemURI("file:///android_asset/www/foo.html", onResolveSuccess, onFail);

然后您可以使用 文件 API - FileEntry.copyTo 或 FileEntry.moveTo 来实际执行操作.注意 - 您实际上无法写入资产/www 文件夹,只能写入 SD 卡.

You can then use the File API - FileEntry.copyTo or FileEntry.moveTo to actually do the action. Note - you cannot actually write into the assset/www folder, only to an SD card.

希望能帮到你

这篇关于从 assets/www 目录访问文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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