I try to GetFile with cordova 3.4.0 :
FileManager.prototype.ReadAsTextFromFile = function (fileName, readDataCallBack) {
var that = this;
try {
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function (fileSystem) {
fileSystem.root.getFile(fileName, {create: false},
function (fileEntry) {
fileEntry.file(
function (file){
var reader = new FileReader();
reader.onloadend = readDataCallBack;
reader.readAsText(file);
}
, function(err){alert('ReadFile' + " fail: " + err.code);});
}
, function(err){alert('GetFile' + " fail: " + err.code);});
}, function(err){alert('FileSystem' + " fail: " + err.code);});
} catch (e) {
logError(e);
}
}
but obtain the err.code 1000 on the call getfile.
the file name is :
var fileName = "/scard/" + reliefsSubfolderName + reliefname
+ String.fromCharCode(47) + reliefsManifestFileName;
/scard/my_dir_on_card/my_file_name.drd (drd is my extension but is a text file)
May I know what is the correct way to achieve my objective?
I guess you need to omit the leading "/" from your fileName.
Most possible cause of Error code 1000 is non-existent path file while geting a reference through getFile with create option as false
fileSystem.root.getFile(fileName, {create: false},...
You may try to inspect the full file path before invoking getFile and see if it is valid. Your path should not contain multiple consecutive "/" other than initial protocol. e.g cdvfile://localhost/persistent/scard.....
console.log(fileSystem.root.toURL() + fileName);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With