O'Reilly logo

PhoneGap 4 Mobile Application Development Cookbook by Zainul Setyo Pamungkas

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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:

  1. Firstly, create a new PhoneGap project named devicestorage by running this line:
    phonegap create devicestorage com.myapp.devicestorage devicestorage
    
  2. Add the devices platform. You can choose to use Android, iOS, or both:
    cordova platform add ios
    cordova platform add android
    
  3. Add the file plugin by running the following line:
    phonegap plugin add org.apache.cordova.file ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required