javascript - Phonegap - How to access file in www-folder? -


How have I seen more than one solution, how can I use a file in the www folder but any solution for me Does not work with iOS-simulator test under iOS application.

FilePathURI: I want to use the file test.txt in the www folder

my current solution looks like this = GetPhoneGapPath ( ) + "Test.txt"; Window.resolveLocalFileSystemURI (FilePathurieri, HonorSalesWeb, Onfile); Function getPhoneGapPath () {'strict experiment'; Var path = window.location.pathname; Var PhoneGadgetPath = Path.Superring (0, PathList IndexOff ('/') + 1); Return phonegappath; };

This solution does not work for me I get an error with errorCode = 2 , which clearly FileError.SECURITY_ERR Means Although I try with, resolveLocalFileSystemURI I can not use to file.
Information:.

    filePathURI > /Users/UserName/Library/Application%20Support/iPhone%20Simulator/7.0/Applications/GUID/AppName. App / www / test.txt
  1. file: /// users / usernames / library / application% 20Support / iPhone% 20Simulator / 7.0 / application / GUID / AppName.app / Www / test.txt

Can anyone give me a job solution?

I recommend using the solutionLocalFileSystemURL method PhoneGrap's file plugin You can use the cordova.file.application directory property to access where the www folder is located.

Ensure that you install the plug-in: $ Cordoba plugin org.apache.cordova.file add

Then you can type files like this Parsing and whatever you need to do, one object can be used as the following:

  on FileManager = {/ ** * All files and directories in the www folder of the phonegap Against this.entryHandler executed * / run: function () {window.resolveLocalFileSystemURL (cordova.file.applicationDirectory + 'www /', this.directoryFoundHandler, it.errorist); }, / ** * The directory has been successfully read Read entries now * * @ The Ultimate {DirectoryEntry} directoryInterior * / DirectoryFoundHandler: Function (DirectoryEnter) {var directoryReader = directoryEntry.createReader (); DirectoryReader.readEntries (this.entryHandler, this.errorHandler); }, / ** * files successfully found. Parsing them! * * @ Ultimate {array and file} entry * / entry handler: Functions (entries) {entries.forEach (function) {// Deal with your files here (entry. This directory) {// This is a directory It may again require a loop again) other {// it is a file, do something}}); }, / ** * @complete {FileError} error * / errorHandler: function (error) {console.log ("error", error); }};  

Comments