简体   繁体   English

Phonegap Android 使用 JavaScript 读取 sdcard 上的文件

[英]Phonegap Android read file on sdcard with JavaScript

I am trying to read a text file with JavaScript using Phonegap 2.0.0 on Android.我正在尝试在 Android 上使用 Phonegap 2.0.0 使用 JavaScript 读取文本文件。 I went over several examples using the File API at http://docs.phonegap.com/en/2.0.0/cordova_file_file.md.html#File Nothing seems to work.我在http://docs.phonegap.com/en/2.0.0/cordova_file_file.md.html#File 上使用 File API 浏览了几个示例,似乎没有任何效果。

I read several related threads on Stackoverflow, for example:我在 Stackoverflow 上阅读了几个相关的线程,例如:

How to read file in android using PhoneGap Javascript 如何使用PhoneGap Javascript在android中读取文件

Android HTML5 FileApi can i read file from SD Card? Android HTML5 FileApi 可以从 SD 卡读取文件吗?

and How to create a new file among others.以及如何创建一个新文件等等。 Yet none of the techniques seem to work.然而,这些技术似乎都不起作用。

I am using Nexus One with API 8. The android app loads a URL: http://www.mydomain.com/read_text_file.html which contains the JavaScript utilizing the PhoneGap framework.我正在使用带有 API 8 的 Nexus One。Android 应用程序加载一个 URL: http : //www.mydomain.com/read_text_file.html ,其中包含利用 PhoneGap 框架的 JavaScript。 I am trying to access a file on the SD card located at: /sdcard/textfile.txt .我正在尝试访问位于以下位置的 SD 卡上的文件: /sdcard/textfile.txt I specify the path to the file in the JavaScript as: file:///sdcard/textfile.txt我在 JavaScript 中指定文件的路径为: file:///sdcard/textfile.txt

For the time being my goal is to trigger an alert from the JavaScript upon page load and show the file contents ( which is just "test file" )目前我的目标是在页面加载时触发来自 JavaScript 的警报并显示文件内容(这只是“测试文件”)

In Place of "file:///sdcard/textfile.txt" try to use only "textfile.txt" .代替 "file:///sdcard/textfile.txt"尝试只使用"textfile.txt"

It seems to work fine.它似乎工作正常。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM