我正在尝试在外部SDCard上创建一个目录。我能够在内部SD上这样做。下面的代码将返回错误代码12.我做错了什么?
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fs) {
console.log("Root = " + fs.root.fullPath);
fs.root.fullPath = cordova.file.externalRootDirectory;
fs.root.getDirectory("newDir", {create: true, exclusive: false},
function(dirEntry) {
dirEntry.getFile("newFile.txt", {create: true, exclusive: false}, function (fileEntry) {
console.log("File = " + fileEntry.fullPath);
}, function (error) {
alert(error.code);
});
}, function (error) {
alert(error.code);
});
}, function (error) {
alert(error.code);
});
答案 0 :(得分:6)
尝试使用: window.resolveLocalFileSystemURL 这很好用
window.resolveLocalFileSystemURL(cordova.file.externalRootDirectory, function(fileSystem) {
console.log("Root = " + cordova.file.externalRootDirectory);
fileSystem.getDirectory("newDir", {create: true, exclusive: false},
function(dirEntry) {
dirEntry.getFile("newFile.txt", {create: true, exclusive: false}, function (fileEntry) {
console.log("File = " + fileEntry.fullPath);
}, function (error) {
alert(error.code);
});
}, function (error) {
alert(error.code);
});
}, function (error) {
alert(error.code);
});