![](/img/trans.png)
[英]Swift: How to copy files from app bundle to Documents folder when app runs for first time
[英]How to copy a file from app bundle to the Documents folder with Cordova?
是的,应该有可能。 让我们认为该文件位于www/en_US.json
因此当您引用它时,使用的路径应该是en_US.json
。 另一方面,目标是由File插件指定的cordova.file.documentsDirectory
。 因此,现在您知道路径了,您需要做的是使用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);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.