【问题标题】:Cordova file copy from www folder to data/dataCordova 文件从 www 文件夹复制到数据/数据
【发布时间】:2017-04-16 14:10:47
【问题描述】:

我在我的data.txtfile www ionic 应用程序文件夹中放置了一个文件。我只想将此文件复制到另一个文件夹,更具体地说是在 data/data 文件夹中。在复制之前我写了一个代码来检查它是否存在?

function checkIfFileExists(path) {
        alert("file path : " + path);
        window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function (fileSystem) {
            fileSystem.root.getFile(path, { create: false }, fileExists, fileDoesNotExist);
        }, getFSFail); //of requestFileSystem
    }
    function fileExists(fileEntry) {
        alert("File " + fileEntry.fullPath + " exists!");
    }
    function fileDoesNotExist() {
        alert("file does not exist");
    }
    function getFSFail(evt) {
        console.log(evt.target.error.code);
    }

    checkIfFileExists(cordova.file.applicationDirectory + 'www/index.html');

此代码返回file does not exist 为什么??

这就是我无法复制我的数据库文件的原因。如果不是这样,任何人都可以帮助使用cordova 应用程序中的预填充数据库。

【问题讨论】:

    标签: cordova ionic-framework


    【解决方案1】:

    您可以使用此插件将数据库从 www 文件夹复制到本机 SQL 数据库。

    https://github.com/an-rahulpandey/cordova-plugin-dbcopy

    示例用法:

    window.plugins.sqlDB.copy(dbname, location, success,error);
    

    然后使用这个插件访问数据库。

    https://github.com/litehelpers/Cordova-sqlite-storage/blob/storage-master/README.md

    示例用法。

    var db = null;
    
    document.addEventListener('deviceready', function() {
          db = window.sqlitePlugin.openDatabase({name: 'demo.db', location: 'default'});
    });
    

    【讨论】:

    • 我实际上是在使用Corodova-sqlite-storage 插件来处理sqlite。当我使用浏览器时,它工作正常。但我希望我的预填充数据库在移动设备中。这就是为什么我将数据库放在www 文件夹中并想复制的原因。
    • 我列出的第一个插件会将预先填充的数据库从 www 复制到本地 sqlite。您所要做的就是将数据库文件包含在 www 文件夹中,然后按照文档移动数据库。
    猜你喜欢
    • 1970-01-01
    • 2016-10-23
    • 2014-01-02
    • 2018-09-04
    • 2012-10-03
    • 1970-01-01
    • 2013-09-19
    • 2013-04-27
    • 1970-01-01
    相关资源
    最近更新 更多