IO

The IO Object contains several properties that can be used to more easily navigate the filesystem.

The functionality in this object allows you to easily access folders on your device like the SDCard, home or sharedFolder. It also allows you to control whether the filesystem is sandboxed or not.

Installation:

To use this API in your project, add the io plugin:

webworks plugin add com.blackberry.io

Example:

<script type="text/javascript">

function readFile() {
    // un-sandbox file system to access shared folder
    blackberry.io.sandbox = false;

    window.requestFileSystem  = window.requestFileSystem || window.webkitRequestFileSystem;

    window.requestFileSystem(window.TEMPORARY, 1024 * 1024,
        function (fs) {
             // in order to access the shared folder,
             // config.xml must declare the "access_shared" permission
             // reference file by absolute path since file system is un-sandboxed
             fs.root.getFile(blackberry.io.sharedFolder + '/Documents/log.txt', {create: true},
                 function (fileEntry) {
                     fileEntry.file(function (file) {
                         var reader = new FileReader();

                         reader.onloadend = function (e) {
                             var txtArea = document.createElement('textarea');
                             txtArea.value = this.result;
                             document.body.appendChild(txtArea);
                         };

                         reader.readAsText(file);
                    }, errorHandler);
                 }, errorHandler);
        });
}

function errorHandler(e) {
    var msg = '';

    switch (e.code) {
    case FileError.QUOTA_EXCEEDED_ERR:
        msg = 'QUOTA_EXCEEDED_ERR';
        break;
    case FileError.NOT_FOUND_ERR:
        msg = 'NOT_FOUND_ERR';
        break;
    case FileError.SECURITY_ERR:
         msg = 'SECURITY_ERR';
         break;
    case FileError.INVALID_MODIFICATION_ERR:
         msg = 'INVALID_MODIFICATION_ERR';
         break;
    case FileError.INVALID_STATE_ERR:
         msg = 'INVALID_STATE_ERR';
         break;
    default:
         msg = 'Unknown Error';
        break;
    };

    console.log('Error: ' + msg);
}

</script>
            
Properties:
String SDCard
String home
Boolean sandbox
String sharedFolder

SDCard

The full file path for the SD card folder.

Synopsis:

read-only
String blackberry.io.SDCard

home

The full file path for the application data folder

Synopsis:

read-only
String blackberry.io.home

sandbox

Whether the file system is sandboxed. It is set to true by default.

When sandbox is set to false, you must use absolute path to reference a file or directory, you can use sharedFolder, home or SDCard to construct file paths.

Synopsis:

Boolean blackberr.io.sandbox = true

sharedFolder

The full file path for the shared folder.

Synopsis:

read-only
String blackberry.io.sharedFolder

Last modified: 2014-03-10