我一直在尝试使用cordova 将名为versions.txt 的文件从applicationDirectory 复制到externalApplicationStorageDirectory,但代码失败。
这是代码
var path = cordova.file.applicationDirectory + "www/Data/versions.txt";
window.resolveLocalFileSystemURL(path,
function gotFile(fileEntry)
{
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0,
function onSuccess(fileSystem)
{
var directory = new DirectoryEntry("versions.txt", path);
fileEntry.copyTo(directory, 'versions.txt',
function()
{
alert('copying was successful')
},
function()
{
alert('unsuccessful copying')
});
}, null);
},null);
Run Code Online (Sandbox Code Playgroud)
有什么帮助吗?
现在可以了,目标目录应该已解析。
这是解决方案
window.resolveLocalFileSystemURL(cordova.file.externalApplicationStorageDirectory,
function onSuccess(dirEntry)
{
//alert(JSON.stringify(dirEntry));
fileEntry.copyTo(dirEntry, 'versions.txt',
function()
{
alert('copying was successful')
},
function()
{
alert('unsuccessful copying')
});
}, null);
Run Code Online (Sandbox Code Playgroud)