如何使用phonegap检查电话目录中的文件是否存在 [英] How to check a file's existence in phone directory with phonegap
本文介绍了如何使用phonegap检查电话目录中的文件是否存在的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在编写一个带有 Phonegap 1.4.1 和 Sencha 的 Android 应用程序,用于下载和读取 pdf 文件.如何使用 phonegap 方法、javascript 或 ajax 检查电话目录中是否存在文件?
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?
推荐答案
您可以使用 phonegap 中的 FileReader 对象检查文件是否存在.您可以检查以下内容:
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(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);
这篇关于如何使用phonegap检查电话目录中的文件是否存在的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文