File
The File object provides functions for interacting with the file system.
See also blackberry.io.dir
Warning ( Playbook 1.0 Notice):
For URI based APIs, webworks:// has been deprecated and replaced with http://localhost:8472. This change does not affect the procedural APIs.
Supported Platform(s)
- BlackBerry OS 5.0+
- BlackBerry PlayBook
View Supported Platform Table
Configuration Document Settings
To use all of the API described for this object, you must ensure the following settings are in your configuration document:
You must declare the feature element(s) below in your configuration document:
Feature ID | OS 5.0 | OS 6.0 | OS 7.0 | PlayBook | Ripple |
<feature id="blackberry.io.file" />
| Y |
Y |
Y |
Y | |
Permission Elements (PlayBook Only) |
Note: Declaring the permission element(s) below in your configuration document is optional.
|
- <rim:permit>access_shared</rim:permit> Any references to files/directories under "shared" folder (e.g. music) requires this permission to be set.
|
copy
static
void
copy(sourcePath : String, targetPath : String)
|
Supported Platform(s)
- BlackBerry OS 5.0+
- BlackBerry PlayBook
Description
Copy a file to a given destination.
Parameter
|
Type
|
Description
|
sourcePath |
String
|
local storage file path to the file to be copied
|
targetPath |
String
|
local storage file path to the new copied file. The name of the copied file should be specified at the end of the targetPath.
|
deleteFile
static
void
deleteFile(path : String)
|
Supported Platform(s)
- BlackBerry OS 5.0+
- BlackBerry PlayBook
Description
Delete a given file.
Parameter
|
Type
|
Description
|
path |
String
|
local storage file path to the file to be deleted
|
exists
static
Boolean
exists(path : String)
|
Supported Platform(s)
- BlackBerry OS 5.0+
- BlackBerry PlayBook
Description
Check whether or not a given file exists.
Parameter
|
Type
|
Description
|
path |
String
|
local storage file path to the file
|
getFileProperties
Supported Platform(s)
- BlackBerry OS 5.0+
- BlackBerry PlayBook
Description
Get the FileProperties object for a given file.
Parameter
|
Type
|
Description
|
path |
String
|
local storage file path to the file
|
open
static
Boolean
open(path : String)
|
Supported Platform(s)
- BlackBerry OS 5.0+
- BlackBerry PlayBook
Description
Open the specified file with the registered content handler.
Parameter
|
Type
|
Description
|
path |
String
|
file path to the file to be opened.
|
readFile
static
void
readFile(path : String, onFileOpened : function, [async: Boolean])
|
Supported Platform(s)
- BlackBerry OS 5.0+
- BlackBerry PlayBook
Description
Reads in a file from the local file system.
Parameter
|
Type
|
Description
|
path |
String
|
local storage file path to the file to be opened into a Blob
|
onFileOpened |
function(fullPath : String, blobData : Blob)
|
callback function to call on completion of loading the file from the file system.
fullPath: full path of the file that was just opened
blobData: blob that contains the file's contents
|
async |
Boolean
Optional
|
a flag specifying if the call to read should be asynchronous or synchronous. If this parameter is not supplied the default of true will be used.
|
rename
static
void
rename(path : String, newFileName : String)
|
Supported Platform(s)
- BlackBerry OS 5.0+
- BlackBerry PlayBook
Description
Rename a given file.
Parameter
|
Type
|
Description
|
path |
String
|
local storage file path to the file
|
newFileName |
String
|
the new file name.
|
saveFile
static
void
saveFile(path : String, data : Blob)
|
Supported Platform(s)
- BlackBerry OS 5.0+
- BlackBerry PlayBook
Description
Save a Blob to the local file system.
Parameter
|
Type
|
Description
|
path |
String
|
Local storage file path to the file that is going to store the data
|
data |
Blob
|
The Blob to be saved.
|
Code Example(s)
<script type="text/javascript">
var xmlString = "<test>IO functions</test>";
var filePath = "file:///store/home/user/sample.xml";
var parser = new DOMParser();
var doc = parser.parseFromString(xmlString, "text/xml");
var blob_data = blackberry.utils.documentToBlob(doc);
blackberry.io.file.saveFile(filePath, blob_data);
if (blackberry.io.file.exists(filePath)) {
blackberry.io.file.copy(filePath, "file:///SDCard/myxmlfile2.xml");
blackberry.io.file.readFile(filePath,handleOpenedFile);
}
function handleOpenedFile(fullPath, blobData) {
alert("file opened was: " + fullPath + " which contained " + blobData.length + " bytes");
}
</script>
http://localhost:8472/blackberry/io/file/copy
Supported Platform(s)
- BlackBerry PlayBook
Description
Copy a file to a given destination.
Parameter
|
Type
|
Description
|
path |
String
|
path to the file to be copied, specified in the form of file:/// URL
|
targetPath |
String
|
path to the newly copied file, the name of the copied file should be specified at the end of the targetPath, in the form of file:/// URL
|
Returns
{
"data" : {
"path" : "<path that was passed>",
"targetPath" : "<targetPath that was passed>"
}
}
|
http://localhost:8472/blackberry/io/file/delete
Supported Platform(s)
- BlackBerry PlayBook
Description
Delete the specified file.
Parameter
|
Type
|
Description
|
path |
String
|
path to the file to be deleted, specified in the form of file:/// URL
|
Returns
{
"data" : {
"path" : "<path that was passed>"
}
}
|
http://localhost:8472/blackberry/io/file/exists
Supported Platform(s)
- BlackBerry PlayBook
Description
Determine whether a given file exists or not.
Parameter
|
Type
|
Description
|
path |
String
|
path of the file, specified in the form of file:/// URL
|
Returns
{
"data" : {
"path": "<path that was passed>",
"exists" : true if the path exists and points to a file, false otherwise
}
}
|
http://localhost:8472/blackberry/io/file/get
Supported Platform(s)
- BlackBerry PlayBook
Description
Get properties for a given file.
Parameter
|
Type
|
Description
|
path |
String
|
path to the file, specified in the form of file:/// URL
|
Returns
{
"data" : {
"path" : "<path that was passed>",
"dateCreated" : "<file creation date, in number of milliseconds since UTC>", // only defined if "code" is 0
"dateModified" : "<file modification date, in number of milliseconds since UTC>", // only defined if "code" is 0
"directory" : "<path of directory that contains this file>", // only defined if "code" is 0
"fileExtension" : "<file extension>", // only defined if "code" is 0
"isHidden" : true (if file is hidden) or false (if file is not hidden), // only defined if "code" is 0
"size" : <file size in bytes> // only defined if "code" is 0
}
}
|
Code Example(s)
<script type="text/javascript" src="js/jquery-1.4.2.js"></script>
<script type="text/javascript">
var filePath = encodeURI(blackberry.io.dir.appDirs.app.storage.path + '/myfile.txt');
var reviverFn = function(key, value) {
// construct JS Date object from number of milliseconds since UTC
if (key.toLowerCase().indexOf('date') != -1) {
return new Date(value);
} else {
return value;
}
};
// inspect properties for this file
$.ajax({
url: "http://localhost:8472/blackberry/io/file/get?path=" + filePath,
success: function(result, textStatus, jqXHR){
try {
var resultObj = JSON.parse(result, reviverFn);
alert("code=" + resultObj.code + " msg=" + resultObj.msg);
for (var f in resultObj.data) {
alert(f + ':' + resultObj.data[f]);
}
} catch (e) {
alert('e.message = ' + e.message);
}
}
});
</script>
http://localhost:8472/blackberry/io/file/open
Supported Platform(s)
- BlackBerry PlayBook
Description
Open the specified file with the registered content handler.
Parameter
|
Type
|
Description
|
path |
String
|
path to the file to be opened, specified in the form of file:/// URL
|
Returns
{
"data" : {
"path" : "<path that was passed>"
}
}
|
http://localhost:8472/blackberry/io/file/rename
Supported Platform(s)
- BlackBerry PlayBook
Description
Rename a given file.
Parameter
|
Type
|
Description
|
path |
String
|
path to the file, specified in the form of file:/// URL
|
newFileName |
String
|
new file name
|
Returns
{
"data" : {
"path" : "<path that was passed>",
"newFileName" : "<newFileName that was passed>"
}
}
|
Documentation generated by
JsDoc Toolkit 2.4.0 on Sun Dec 30 2012 13:31:17 GMT-0500 (EST)