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

后端 未结 14 2001
太阳男子
太阳男子 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条回答
  •  Happy的楠姐
    2020-12-05 11:36

    You could check if the file exists using the FileReader object from phonegap. You could check the following:

    var reader = new FileReader();
    var fileSource = 
    
    reader.onloadend = function(evt) {
    
        if(evt.target.result == null) {
           // If you receive a null value the file doesn't exists
        } else {
            // Otherwise the file exists
        }         
    };
    
    // We are going to check if the file exists
    reader.readAsDataURL(fileSource);   
    

提交回复
热议问题