gpt4 book ai didi

javascript - 使用 PhoneGap 将文件从 www 复制到 'Documents'

转载 作者:可可西里 更新时间:2023-11-01 05:30:40 26 4
gpt4 key购买 nike

我正在尝试将存储在 phonegap 文件夹 (www/default_files/file.txt) 中的文件复制到 iOS 中的文档文件夹,到目前为止我得到的是:

window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fileSys)
{
fileSys.root.getFile("file.txt", null, function(theFile){ // file exist don't do anything},
function(error)
{
// file does not exist, so copy it
fileSys.copyTo(fileSys.root.fullPath, "www/default_files/file.txt",
function success(entry)
{
console.log("Success: " + entry);
},
function error(entry)
{
console.log(entry);
});
});
}, fileError);

fileSys.root.fullPath 包含正确的文档路径,问题是如何访问 www 文件夹...

有什么想法吗?

最佳答案

此代码适用于 iOS。此函数实现了将数据库文件从/www 文件夹复制到/Documents 文件夹。

function copyBase(){
var wwwPath = window.location.pathname;
var basePath = 'file://'+ wwwPath.substring(0,wwwPath.length-10);
window.resolveLocalFileSystemURL(basePath+'myDB.db',
function(fileDB){
console.log('success! database was found')
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, onSuccess, null);

function onSuccess(fileSystem) {
var documentsPath = fileSystem.root;
fileDB.copyTo(documentsPath, 'myDB.db',
function(){
console.log('copying was successful')
},
function(){
console.log('unsuccessful copying')
});
}
},
function(){
console.log('failure! database was not found')
});
}

关于javascript - 使用 PhoneGap 将文件从 www 复制到 'Documents',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15327623/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com