Example
Some of the file system operations. For more examples refer to the Android IO sample app.
var storagePath = siteKiosk.io.fileSystem.getStoragePath();
//check if there is such a directory and create it if it's not present
var textDirectory = storagePath+"/texts";
if (!siteKiosk.io.fileSystem.exists(textDirectory)) {
siteKiosk.io.fileSystem.createDirectory(textDirectory, function (errorMessage) {
//error handling goes here
});
}
var path = storagePath+"/sample.txt",
content = "I am a string!",
append = true;
siteKiosk.io.fileSystem.writeTextFile(path,content, append, function (errorMessage) {
//error handling goes here
}
Classes
Methods
-
<static> copy(from, to, completed)
-
Copies a file or directory.
Parameters:
Name Type Description fromstring The path to the file or directory that should be copied tostring The target path completedsiteKiosk.io.fileSystem~copyCallback Callback will be called when operation finished -
<static> createDirectory(path, completed)
-
Creates a directory.
Parameters:
Name Type Description pathstring The path to the directory that should be created completedsiteKiosk.io.fileSystem~createCallback Callback will be called when operation finished -
<static> exists() → {boolean}
-
Checks if the path exists in the file system.
Returns:
Whether the path exists in the file system- Type
- boolean
-
<static> getProperties(path) → {siteKiosk.io.fileSystem~fileProperties}
-
Retrieves the file properties of a given path.
Parameters:
Name Type Description pathstring The path to the file Returns:
Property object -
<static> getStoragePath() → {string}
-
Gets the path to the directory where user data can be stored.
Returns:
The path to the directory where user data can be stored- Type
- string
-
<static> list(path, completed)
-
Lists a directory.
Parameters:
Name Type Description pathstring The path to the file or directory that should be scanned completedsiteKiosk.io.fileSystem~listCallback Callback will be called when operation finished -
<static> open(path, write, completed)
-
Opens a file as a stream for later use.
Parameters:
Name Type Description pathstring The path to the file to be read writeboolean True, if the file should be opened for writing (appending) completedsiteKiosk.io.fileSystem~openCallback Callback will be called when operation finished -
<static> readTextFile(path, completed)
-
Reads text from a file.
Parameters:
Name Type Description pathstring The path to the file to be read completedsiteKiosk.io.fileSystem~readTextFileCallback Callback will be called when operation finished -
<static> remove(path, completed)
-
Removes a file or directory.
Parameters:
Name Type Description pathstring The path to the file or directory that should be removed completedsiteKiosk.io.fileSystem~removeCallback Callback will be called when operation finished -
<static> rename(from, to, completed)
-
Renames a file or directory. Can also be used to move a file.
Parameters:
Name Type Description fromstring The path to the file or directory that should be renamed tostring The target path completedsiteKiosk.io.fileSystem~renameCallback Callback will be called when operation finished -
<static> writeTextFile(path, text, append, completed)
-
Writes text into a file.
Parameters:
Name Type Description pathstring The path to the file that should be written textstring The text to be written to the file appendboolean True, if the text should be appended to the end of the file. Otherwise the existing content is erased completedsiteKiosk.io.fileSystem~writeTextFileCallback Callback will be called when operation finished
Type Definitions
-
copyCallback(errorMessage)
-
A callback which will be called when the operation to copy a file has been completed.
Parameters:
Name Type Argument Description errorMessagestring <nullable>
An error message or null if the operation has been completed successfully -
createCallback(errorMessage)
-
A callback which will be called when the operation to create a file has been completed.
Parameters:
Name Type Argument Description errorMessagestring <nullable>
An error message or null if the operation has been completed successfully -
fileProperties
-
Type:
- Object
Properties:
Name Type Description isDirectoryboolean If this file represents a directory on the underlying file system isHiddenboolean Whether or not this file is a hidden file as defined by the operating system lastModifiedDate The time when this file was last modified sizenumber The length of this file in bytes -
listCallback(errorMessage, list)
-
A callback which will be called when the operation to get a list of files has been completed.
Parameters:
Name Type Argument Description errorMessagestring <nullable>
An error message or null if the operation has been completed successfully list?Array.<string> <nullable>
An array of strings with file names or null -
openCallback(errorMessage, file)
-
A callback which will be called when the operation to open a file stream has been completed.
Parameters:
Name Type Argument Description errorMessagestring <nullable>
An error message or null if the operation has been completed successfully filesiteKiosk.io.fileSystem~File <nullable>
A file object or null -
readTextFileCallback(errorMessage, text)
-
A callback which will be called when the operation to read a text file to the file system has been completed.
Parameters:
Name Type Description errorMessagestring An error message or an empty string if the operation has been completed successfully textstring The text of the file or an empty string id the operation has not been completed successfully -
removeCallback(errorMessage)
-
A callback which will be called when the operation to remove a file from the file system has been completed.
Parameters:
Name Type Argument Description errorMessagestring <nullable>
An error message or null if the operation has been completed successfully -
renameCallback(errorMessage)
-
A callback which will be called when the operation to rename a file on file system has been completed.
Parameters:
Name Type Argument Description errorMessagestring <nullable>
An error message or null if the operation has been completed successfully -
writeTextFileCallback(errorMessage)
-
A callback which will be called when the operation to write a text file to the file system has been completed.
Parameters:
Name Type Description errorMessagestring An error message or an empty string if the operation has been completed successfully