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

后端 未结 14 1992
太阳男子
太阳男子 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:50

    If you need a boolean-compatible method...

    function checkIfFileExists(path){
        var result = false;
    
        window.requestFileSystem(
            LocalFileSystem.PERSISTENT, 
            0, 
            function(fileSystem){
                fileSystem.root.getFile(
                    path, 
                    { create: false }, 
                    function(){ result = true; }, // file exists
                    function(){ result = false; } // file does not exist
                );
            },
            getFSFail
        ); //of requestFileSystem
    
        return result;
    }
    

提交回复
热议问题