How to check a file's existence in phone directory with phonegap

后端 未结 14 2034
太阳男子
太阳男子 2020-12-05 10:49

I\'m writing an Android application with Phonegap 1.4.1 and Sencha that downloads and reads pdf files. How can I check whether the file exists in the phone directory using e

14条回答
  •  孤街浪徒
    2020-12-05 11:33

    I took @Thomas Soti answer above and trimmed it down to a simple yes/no response.

    function fileExists(fileName) {
      window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function(fileSystem){
          fileSystem.root.getFile(cordova.file.dataDirectory + fileName, { create: false }, function(){return true}, function(){return false});
      }, function(){return false}); //of requestFileSystem
    }
    // called as
    if (fileExists("blah.json")) {
    or
    var fe = fileExists("blah.json) ;
    

    Correction....this does NOT work. I am working on the fix now.

提交回复
热议问题