The Cordova File API provides an application with the methods it needs to interact with the device’s local file system. The API exposes methods an application can use to browse the file system, read, write, copy, move and remove files. An application cannot access just any part of the file system, only the temporary and persistent file storage locations (described below) on a mobile device.

An application would use this API to read and write files on the device file system. An application might use one of the many available storage options for web application to store application data, but developers can also use the file system to persist application settings or application data using the file system, writing text files (in XML or JSON format for example) as needed while the application runs. Additionally, remember that the Camera (Chapter 3) and Capture (Chapter 4) APIs write their files to the file system, applications use the File API to manipulate those files as needed.

Two sample applications are included to help illustrate the features of the File API. The application creates a directory browser application that allows the user to select one of the available storage locations (described in the following section) the read the high-level directory entries for the selected location. The applications can also create a new file, view a file’s contents and remove a file from the file system. The two applications are almost identical, the only difference between the two is in how the applications write to a local file. I explain more about this in the chapter content that follows.

A third example is included, with client and server code, that illustrates how to transfer files to and from a remote file server.