Returns the content of the specified file as string.
$m.readFile("offline_orders.txt", 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; } if(response.code){ var fileContent = response.result; } else{ // show error as toast message. $m.toast(response.error.message); } }); |
Syntax
$m.readFile(filePath[, fp_callback])
$m.getFilePath(file[, 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.
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,
- code - {Number}. Possible codes are,
- -1 - Storage is not ready.
- 1 - File path is successfully read.
- 0 - Error in reading file path.
- result - {String}. The content of the file.
- error - {Object}. Available when the code is 0. The error object contains,
- message - {String}. A short description of the error.
- description - {String}. A detailed description of the error.