![](/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.