user992804 user992804 - 1 year ago 85
Ajax Question

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

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 either phonegap methods, javascript or ajax?

Answer Source

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

var reader = new FileReader();
var fileSource = <here is your file path>

reader.onloadend = function(evt) {

    if( == 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
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download