从资产/ www目录访问文件 [英] access files from assets/www directory
问题描述
让我们说我在我的资产/ www目录(明年到我的index.html)得到了 foo.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,凉(),notCool());
不工作。还搭配了preFIX类似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的访问文件。我不相信,因此希望看到一个code段如何获取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错误:未定义
(PhoneGap的V1.2)和 code:1
与V1.0(code没有发现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实际上做的动作。注 - 你不能真正写进assset /网络文件夹,只有到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.
希望这有助于
这篇关于从资产/ www目录访问文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!