writeFile

File

Writes the string content to the specified file.

$m.writeFile("offline_orders.txt", "welcome to mowbly", function(response) {

     if(response.code == -1) {

          // External storage is not ready. Possible reason could be the storage

          // is mounted to file system on a computer.

          return;

     }

     var message;        

     if(response.result){

        message = "Successfully written to the file.";

        } else{

            message = response.error.message;

        }

     $m.toast(message);

});

Syntax

        $m.writeFile(filePath, content[, fp_callback])

        $m.writeFile(file, content[, fp_callback])

Parameters

filePath

string (required)

The path of the file relative to the pack folder.

file

file (required)

The mowbly file object. Use getFile method to create the mowbly file object. The advantage of using file over filePath parameter is that file object provides options to specify the path relative to the application folder or storage root apart from pack.

content

string (required)

The string content to be written to the file.

fp_callback

function (optional)

Function that is invoked when the file content is read. The function receives a response object as parameter with the following properties,

  1. code - {Number}. Possible codes are,
  1. -1 -  Storage is not ready.
  2. 1  - File path is successfully read.
  3. 0  - Error in reading file path.

  1. result - {Boolean}. True, if the write operation is successful. False, otherwise.

  1. error - {Object}. Available when the code is 0. The error object contains,
  1. message - {String}. A short description of the error.
  2. description - {String}. A detailed description of the error.