Opening a local file from the device storage
While developing your mobile application, you may need or want to read particular files from the storage system or from another location on the device.
How to do it…
In this recipe, we will build an application that will create a text file on the phone's storage filesystem, write content to the file, and then open the file to display the content:
- Firstly, create a new PhoneGap project named
devicestorage
by running this line:phonegap create devicestorage com.myapp.devicestorage devicestorage
- Add the devices platform. You can choose to use Android, iOS, or both:
cordova platform add ios cordova platform add android
- Add the
file
plugin by running the following line:phonegap plugin add org.apache.cordova.file
- We're going to use the
XUI
JavaScript library to easily access the DOM elements, so we'll include the reference to the file within thehead
tag. - Open
www/index.html
and clean up the unnecessary elements. So, we will have this...