admin管理员组文章数量:1419184
I am trying to read a file using cordova with this code. But I am not able to see alert inside fileSystem.root.getFile
function.
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0,
function (fileSystem) {
alert("root name=" + fileSystem.root.name); //alert working
//after this not working
var path = "index.html";
fileSystem.root.getFile(path, null, function (fileEntry) {
alert('file entry');
fileEntry.file(gotFile, fail);
}, fail);
}, fail);
function fail(error) {
alert("File System Error:" + error.code);
}
I get error code 1
. I am using visual studio cordova hybrid app plugin (2013).
Update Solved:
I solved the problem by going to my bin -> windows phone directory. And then i renamed the .xap file to .zip to extract the content. I found there that my files are correctly deployed along with cordova plugins. But my files were inside www
directory. So i sepcified the path and it works now;
var path = "www/index.html";
But i am really wondering why cordova documentation didn't mention this but anyway i solved it now;
I am trying to read a file using cordova with this code. But I am not able to see alert inside fileSystem.root.getFile
function.
window.requestFileSystem(LocalFileSystem.PERSISTENT, 0,
function (fileSystem) {
alert("root name=" + fileSystem.root.name); //alert working
//after this not working
var path = "index.html";
fileSystem.root.getFile(path, null, function (fileEntry) {
alert('file entry');
fileEntry.file(gotFile, fail);
}, fail);
}, fail);
function fail(error) {
alert("File System Error:" + error.code);
}
I get error code 1
. I am using visual studio cordova hybrid app plugin (2013).
Update Solved:
I solved the problem by going to my bin -> windows phone directory. And then i renamed the .xap file to .zip to extract the content. I found there that my files are correctly deployed along with cordova plugins. But my files were inside www
directory. So i sepcified the path and it works now;
var path = "www/index.html";
But i am really wondering why cordova documentation didn't mention this but anyway i solved it now;
Share Improve this question edited Nov 15, 2014 at 21:26 Priyank 1,56810 silver badges15 bronze badges asked Aug 19, 2014 at 15:42 Idrees KhanIdrees Khan 7,75218 gold badges64 silver badges112 bronze badges 10- Hi, can you add the platform where you got this error code? – Nicolas R Commented Aug 25, 2014 at 12:28
- @NicolasR in windows phone – Idrees Khan Commented Aug 25, 2014 at 12:29
- Windows Phone 8? 8.1? – Nicolas R Commented Aug 25, 2014 at 12:30
- windows phone 8 because by default, cordova plugin for visual studio start wp 8 simulator but i deploy to wp8.1 still the same error – Idrees Khan Commented Aug 25, 2014 at 12:31
- Maybe you can try to list the directories in your storage to ensure that you really are where you think you are, like the OP of this question did: stackoverflow./questions/24600166/… Thats sounds basic, but with all the isolatedStorage part in WP, maybe you should check – Nicolas R Commented Aug 25, 2014 at 12:53
4 Answers
Reset to default 2 +50I just posted an answer to a similar question with working code example here: Loading an array stored in a text file in phonegap
I think Abhishek's answer is quite helpful by the way.
Error is reported because fileSystem.root.getFile
is not able to find index.html at location pointed by LocalFileSystem.PERSISTENT. You can log fileSystem.root.fullPath
to find the path where fileSystem.root.getFile()
is looking into in your device or system.
Your apps files like index.html are not stored or dropped at LocalFileSystem.PERSISTENT unless it is explicitly copied there. You can find more detail on where LocalFileSystem.PERSISTENT points in SO question Where does LocalFileSystem.PERSISTENT point to?
Try:
var path = "./index.html";
You should concatenate the filesystem.root.name and your current path to create an absoulte path to the location of the file relative to the phone file system, then pass that into the path parameter of fileSystem.root.getFile. Right now your path is inplete. Hope it helps!!
本文标签: javascriptApache Cordova Can39t Read a File from Root DirectoryStack Overflow
版权声明:本文标题:javascript - Apache Cordova Can't Read a File from Root Directory - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745303612a2652518.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论