Javascript 将文件从www复制到';文件';使用PhoneGap

Javascript 将文件从www复制到';文件';使用PhoneGap,javascript,ios,cordova,Javascript,Ios,Cordova,我正在尝试将存储在phonegap文件夹(www/default_files/file.txt)中的文件复制到iOS中的documents文件夹中,到目前为止,我得到的是: window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fileSys) { fileSys.root.getFile("file.txt", null, function(theFile){ // file exist don't do anyt

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

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文件夹


有什么想法吗?

您可以访问www文件夹,如下所示
/var/mobile/Applications/35--------------------9087/yourapp.app/www/yourfolder/yourfilename.ext

编辑

使用
警报(window.location.pathname)
查找应用程序的路径。

此代码在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')
        });
}
使用。 然后,您可以使用以下字符串访问www文件夹:cordova.file.applicationDirectory+“www/” 和使用字符串的文档文件夹:
cordova.file.documents目录。

您可以使用
cordova.file.applicationDirectory
而不是hacky www路径。