如何检查存储中存在的下载文件

时间:2014-03-12 05:54:43

标签: android ios jquery-mobile cordova

我将PDF文件存储在某个路径中。如果我下载了该文件,则再次点击下载链接如何发出警报"你已经下载了这个文件。您想重新下载"?

function downloadFile(){

window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, 
    function onFileSystemSuccess(fileSystem) {
        fileSystem.root.getFile(
        "dummy.html", {create: true, exclusive: false}, 
        function gotFileEntry(fileEntry) {
            var sPath = fileEntry.fullPath.replace("dummy.html","");
            var fileTransfer = new FileTransfer();
            fileEntry.remove();

            fileTransfer.download(
                "http://www.w3.org/2011/web-apps-ws/papers/Nitobi.pdf",
                sPath + "theFile.pdf",
                function(theFile) {
                    console.log("download complete: " + theFile.toURI());
                    showLink(theFile.toURI());
                },
                function(error) {
                    console.log("download error source " + error.source);
                    console.log("download error target " + error.target);
                    console.log("upload error code: " + error.code);
                }
            );
        }, fail);
    }, fail);
};
}

1 个答案:

答案 0 :(得分:0)

这是一个非常好的问题,所以我在这种情况下简要解释一下我们要检查2条件杉木

  1. 在该文件路径上文件名不存在的IS文件然后我们必须下载文件
  2. 如果该文件中存在文件名,那么你必须检查该文件的MD5 ,因为同名的另一个文件也可能存在,所以在此条件我们必须使用文件MD5

    检查文件内容
    private File longF ;
    private MessageDigest md;
    longF = "your file path which u want to check weather it is present or not ";
    String digest ="";
    md = MessageDigest.getInstance("MD5");
    
            if(longF.exists())
                              {
                         digest = Constant.getDigest(new FileInputStream(longF), md, 2048);
                              }
                    else
                        {
                                System.out.println("not already exit according to file path condition " );
    
                              } 
    
                 if(digest.equals(selectMD5))
            {
                System.out.println("Open That file=========");
                    }