如何使用javascript在移动SD卡中检查文件是否存在

时间:2015-04-01 11:54:25

标签: javascript cordova filereader android-sdcard filewriter

如何使用PhoneGap检查Android上的SD卡上是否存在Excel文件(.xlsx)?如果文件退出,我如何通过javascript导入和导出文件内容?

1 个答案:

答案 0 :(得分:0)

首先将cordova File插件添加到您的项目中。然后使用以下代码:

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

    reader.onloadend = function(evt) {

        if(evt.target.result != null) {
            // If you receive not null value the file exists
        } else {
            // Otherwise the file doesn't exists
        }         
    };

    // We are going to check if the file exists
    reader.readAsDataURL(fileSource);