0
如何使用Cordova file API将文件从应用程序包(只读)复制到Documents文件夹(读写)?有没有可能使用an additional plugin?如何使用Cordova将应用程序包中的文件复制到Documents文件夹中?
如何使用Cordova file API将文件从应用程序包(只读)复制到Documents文件夹(读写)?有没有可能使用an additional plugin?如何使用Cordova将应用程序包中的文件复制到Documents文件夹中?
是的,应该是可以的。让我们认为该文件位于www/en_US.json
,所以当你引用它时,使用的路径应该是en_US.json
。另一方面,目的地是cordova.file.documentsDirectory
,由File插件指定。所以,现在你知道路径,你需要做的就是用File插件复制文件。这里是完全没有测试的例子,但应该给你的主要想法:
function copyFileToDocuments(fileToBeCopied) {
function gotFileEntry(fileEntry) {
fileEntry.copyTo(cordova.file.documentsDirectory);
}
function onFileSystemSuccess(fileSystem) {
window.resolveLocalFileSystemURL(this.getDirectory(), function(dirEntry) {
dirEntry.getFile(fileToBeCopied, {create: true, exclusive: false}, gotFileEntry.bind(this), this.errorHandler);
}.bind(this));
}
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, onFileSystemSuccess.bind(this), this.errorHandler);
}