cordova plugin file code example

Example 1: cordova js how to load local file in subdir

var path = window.location.href.replace('index.html', '');
var jsonFile = path + "menus/" + menuc + ".json";
$.getJSON(jsonFile, function(result) {
    sortAllergies(result);
});

Example 2: cordova read file in www folder

function listDir(path){
  window.resolveLocalFileSystemURL(path,
    function (fileSystem) {
      var reader = fileSystem.createReader();
      reader.readEntries(
        function (entries) {
          console.log(entries);
        },
        function (err) {
          console.log(err);
        }
      );
    }, function (err) {
      console.log(err);
    }
  );
}
//example: list of www/ folder in cordova/ionic app.
listDir(cordova.file.applicationDirectory + "www/");

Tags:

Misc Example