filesystem api the filesystem api provides access to a device's filesystem the filesystem is represented as an abstract collection of disjointed filesystem virtual root locations, each corresponding to a specific location in the device filesystem the filesystem api exposes the hierarchies below these root locations as autonomous virtual filesystems each virtual root has a string name each file or directory within the virtual filesystem is addressed using a fully-qualified path of the form <root name>/<path> where <rootname> is the name of the virtual root and <path> is the path to the file or directory relative to that root the following virtual roots must be supported images - the location for images videos - the location for videos music - the location for sounds documents - the location for documents downloads - the location for downloaded items camera - the location for the pictures and videos taken by a device supported since tizen 2 3 wgt-package - the location for widget package which is read-only wgt-private - the location for a widget's private storage wgt-private-tmp - the location for a widget's private volatile storage removable_ - the location for external storages the " " suffix is a unique identifier of an external storage to obtain list of available external storages use liststorages the file uri path is also supported to access paths out of virtual root, for example "file ///tmp" can be used as location parameter the implementation must support the use of the following characters in file names letters a-z, a-z digits 0-9 blank space underscore "_" hyphen "-" period " " the implementation may support additional characters in file names, depending on platform support the implementation may forbid the use of additional characters in file names, depending on the platform the use of the path component separator "/" and null character "x00" should not be allowed in file names some other file name and path characteristics are platform-dependent, for example, maximum path length, file name length, case sensitivity, additional character support, etc therefore, it is recommended to avoid any dependency on aspects that cannot be supported across multiple platforms the encoding used for the file path should be utf-16 default for ecmascript string remark in order to access files, a proper privilege has to be defined additionally for accessing only internal storage using this api, a privilege http //tizen org/privilege/mediastorage must be provided, for accessing only external storage using this api, a privilege http //tizen org/privilege/externalstorage must be provided, for accessing internal and external storage using this api, privileges http //tizen org/privilege/mediastorage and http //tizen org/privilege/externalstorage must be provided remark methods, which names end with nonblocking are asynchronous and are executed in background in the order in which they were called corresponding methods without nonblocking at the end are synchronous and will block further instructions execution, until they are finished for more information on the filesystem features, see file system guide since 1 0 summary of interfaces and methods interface method filesystemmanagerobject filesystemmanager filehandle openfile path path, filemode openmode, optional boolean makeparents void createdirectory path path, optional boolean makeparents, optional pathsuccesscallback? successcallback, optional errorcallback? errorcallback void deletefile path path, optional pathsuccesscallback? successcallback, optional errorcallback? errorcallback void deletedirectory path path, optional boolean recursive, optional pathsuccesscallback? successcallback, optional errorcallback? errorcallback void copyfile path sourcepath, path destinationpath, optional boolean overwrite, optional pathsuccesscallback? successcallback, optional errorcallback? errorcallback void copydirectory path sourcepath, path destinationpath, optional boolean overwrite, optional pathsuccesscallback? successcallback, optional errorcallback? errorcallback void movefile path sourcepath, path destinationpath, optional boolean overwrite, optional pathsuccesscallback? successcallback, optional errorcallback? errorcallback void movedirectory path sourcepath, path destinationpath, optional boolean overwrite, optional pathsuccesscallback? successcallback, optional errorcallback? errorcallback void rename path path, domstring newname, optional pathsuccesscallback? successcallback, optional errorcallback? errorcallback void listdirectory path path, listdirectorysuccesscallback successcallback, optional errorcallback? errorcallback, optional filefilter? filter domstring touri path path boolean isfile path path boolean isdirectory path path boolean pathexists path path domstring getdirname domstring path void getstorage domstring label, filesystemstoragesuccesscallback onsuccess, optional errorcallback? onerror void liststorages filesystemstoragearraysuccesscallback onsuccess, optional errorcallback? onerror long addstoragestatechangelistener filesystemstoragesuccesscallback onsuccess, optional errorcallback? onerror void removestoragestatechangelistener long watchid filesystemstorage filehandle long long seek long long offset, optional baseseekposition whence void seeknonblocking long long offset, optional seeksuccesscallback? onsuccess, optional errorcallback? onerror, optional baseseekposition whence domstring readstring optional long long? count, optional domstring inputencoding void readstringnonblocking optional readstringsuccesscallback? onsuccess, optional errorcallback? onerror, optional long long count, optional domstring inputencoding long long writestring domstring inputstring, optional domstring outputencoding void writestringnonblocking domstring inputstring, optional writestringsuccesscallback? onsuccess, optional errorcallback? onerror, optional domstring outputencoding blob readblob optional long long size void readblobnonblocking optional readblobsuccesscallback? onsuccess, optional errorcallback? onerror, optional long long? size void writeblob blob blob void writeblobnonblocking blob blob, optional successcallback? onsuccess, optional errorcallback? onerror uint8array readdata optional long long size void readdatanonblocking optional readdatasuccesscallback? onsuccess, optional errorcallback? onerror, optional long long? size void writedata uint8array data void writedatanonblocking uint8array data, optional successcallback? onsuccess, optional errorcallback? onerror void flush void flushnonblocking optional successcallback? onsuccess, optional errorcallback? onerror void sync void syncnonblocking optional successcallback? onsuccess, optional errorcallback? onerror void close void closenonblocking optional successcallback? onsuccess, optional errorcallback? onerror filefilter filesystemstoragearraysuccesscallback void onsuccess filesystemstorage[] storages filesystemstoragesuccesscallback void onsuccess filesystemstorage storage pathsuccesscallback void onsuccess path path seeksuccesscallback void onsuccess long long position readstringsuccesscallback void onsuccess domstring string writestringsuccesscallback void onsuccess long long bytescount readblobsuccesscallback void onsuccess blob blob readdatasuccesscallback void onsuccess uint8array data listdirectorysuccesscallback void onsuccess domstring[] names, path path 1 type definitions 1 1 path string, which points to file or directory typedef domstring path; since 5 0 in methods available since tizen 5 0, checking or accessing files or directories may be granted only through a valid path paths may contain one of the supported virtual roots the valid path pattern is explained on the top of the page 1 2 filemode specifies the file mode when it is opened enum filemode { "a", "r", "rw", "rwo", "w" }; since 1 0 the file modes defined by this enumerator are a - append access r - read-only access rw - read and write access rwo - read and write access original file content are deleted w - write access remark rwo mode is supported since tizen 5 0 it will not be recognized by deprecated functions 1 3 filesystemstoragetype specifies the type of storage enum filesystemstoragetype { "internal", "external" }; since 1 0 internal - internal storage is a storage that cannot be removed, such as a flash memory external - external storage is removable storage, such as a usb drive or a memory card 1 4 filesystemstoragestate specifies the state of the storage enum filesystemstoragestate { "mounted", "removed", "unmountable" }; since 1 0 mounted - the device is mounted and can be browsed removed - the device has been removed this states applies only to external drives unmountable - the device cannot be mounted due to an error 1 5 blob this is a blob object defined in w3c file api see the blob interface typedef blob blob; since 5 0 1 6 baseseekposition specifies starting point for seek operation enum baseseekposition { "begin", "current", "end" }; since 5 0 begin - beginning of the file current - current position of file indicator end - end of the file 2 interfaces 2 1 filesystemmanagerobject the filesystemmanagerobject interface defines what is instantiated by the tizen object [nointerfaceobject] interface filesystemmanagerobject { readonly attribute filesystemmanager filesystem; }; tizen implements filesystemmanagerobject; since 1 0 there is a tizen filesystem object that allows accessing the functionality of the filesystem api attributes readonly filesystemmanager filesystem object representing a filesystem since 1 0 2 2 filesystemmanager the filesystemmanager interface provides access to the filesystem api [nointerfaceobject] interface filesystemmanager { readonly attribute long maxnamelength; readonly attribute long maxpathlength; filehandle openfile path path, filemode openmode, optional boolean makeparents raises webapiexception ; void createdirectory path path, optional boolean makeparents, optional pathsuccesscallback? successcallback, optional errorcallback? errorcallback raises webapiexception ; void deletefile path path, optional pathsuccesscallback? successcallback, optional errorcallback? errorcallback raises webapiexception ; void deletedirectory path path, optional boolean recursive, optional pathsuccesscallback? successcallback, optional errorcallback? errorcallback raises webapiexception ; void copyfile path sourcepath, path destinationpath, optional boolean overwrite, optional pathsuccesscallback? successcallback, optional errorcallback? errorcallback raises webapiexception ; void copydirectory path sourcepath, path destinationpath, optional boolean overwrite, optional pathsuccesscallback? successcallback, optional errorcallback? errorcallback raises webapiexception ; void movefile path sourcepath, path destinationpath, optional boolean overwrite, optional pathsuccesscallback? successcallback, optional errorcallback? errorcallback raises webapiexception ; void movedirectory path sourcepath, path destinationpath, optional boolean overwrite, optional pathsuccesscallback? successcallback, optional errorcallback? errorcallback raises webapiexception ; void rename path path, domstring newname, optional pathsuccesscallback? successcallback, optional errorcallback? errorcallback raises webapiexception ; void listdirectory path path, listdirectorysuccesscallback successcallback, optional errorcallback? errorcallback, optional filefilter? filter raises webapiexception ; domstring touri path path raises webapiexception ; boolean isfile path path raises webapiexception ; boolean isdirectory path path raises webapiexception ; boolean pathexists path path raises webapiexception ; domstring getdirname domstring path ; void resolve domstring location, filesuccesscallback onsuccess, optional errorcallback? onerror, optional filemode? mode raises webapiexception ; void getstorage domstring label, filesystemstoragesuccesscallback onsuccess, optional errorcallback? onerror raises webapiexception ; void liststorages filesystemstoragearraysuccesscallback onsuccess, optional errorcallback? onerror raises webapiexception ; long addstoragestatechangelistener filesystemstoragesuccesscallback onsuccess, optional errorcallback? onerror raises webapiexception ; void removestoragestatechangelistener long watchid raises webapiexception ; }; since 1 0 this manager interface exposes the filesystem base api and provides functionalities, such as determining root and default locations, resolving a given location into a file handle and registering filesystem listeners for filesystem events attributes readonly long maxnamelength the maximum file or directory name length for the current platform since 5 0 code example console log "the maximum name length is " + tizen filesystem maxnamelength ; output example the maximum name length is 255 readonly long maxpathlength the maximum path length limit for the current platform since 1 0 code example console log "the maximum path length is " + tizen filesystem maxpathlength ; output example the maximum path length is 4096 methods openfile opens a file or creates a file pointed by path filehandle openfile path path, filemode openmode, optional boolean makeparents ; since 5 0 if the operation succeeds, a file handle to the newly created or opened file is returned, otherwise an exception is thrown following file open modes are supported a - append mode file position indicator is always set to the first position after the last character of the file and cannot be modified with seek operations write operations always append content to the end of the file original file content are not modified read operations cannot be performed if the file does not exist, it is created r - read mode file position indicator is initially set to the beginning of the file and may be changed with seek operations write operations cannot be performed original file content may be read in this mode if the file does not exist, notfounderror is thrown rw - read and write mode file position indicator is initially set to the beginning of the file and may be changed with seek operations original file content may be read or modified in this mode if the file does not exist, notfounderror will be thrown rwo - read and write mode, overwriting existing file content file position indicator is initially set to the beginning of the file read and write operations may be performed original file content are deleted before opening the file if the file does not exist, it is created w - write mode file position indicator is initially set to the beginning of the file and may be changed with seek operations read operations cannot be performed original file content are deleted before opening the file if the file does not exist, it is created privilege level public privilege http //tizen org/privilege/filesystem read privilege http //tizen org/privilege/filesystem write remark write permission is needed, when file is opened in modes a, rw, rwo and w read permission is needed, when file is opened in modes r, rw and rwo parameters path path to the file openmode mode in which the file is to be opened makeparents [optional] flag indicating whether lacking directories should be created for instance, if method is invoked with parameter path equal to documents/path/to/dir/file ext and there is no directory "path" in "documents" virtual root, directories "path", "to" and "dir" will be created, as well as the new file "file ext" by default, makeparents is equal to true its value is ignored, when openmode is r or rw return value filehandle object representing open file exceptions webapiexception with error type ioerror, if a file is not available for open or any other io error occurs with error type notfounderror, if the path does not point to an existing file with error type securityerror, if the application does not have the privilege to call this method or the application does not have privilege to access the storage for more information, see storage privileges with error type typemismatcherror, if any of the input parameters is not compatible with the expected type for that parameter code example /* opening file for write - file is created if not exists, */ /* otherwise existing file is truncated */ var filehandlewrite = tizen filesystem openfile "documents/file", "w" ; console log "file opened for writing" ; filehandlewrite writestring "lorem ipsum dolor sit amet " ; console log "string has been written to the file" ; filehandlewrite close ; /* opening file for read - this code assumes that there is */ /* a file named "file" in documents directory */ var filehandleread = tizen filesystem openfile "documents/file", "r" ; console log "file opened for reading" ; var filecontent = filehandleread readstring ; console log "file content " + filecontent ; filehandleread close ; output example file opened for writing string has been written to the file file opened for reading file content lorem ipsum dolor sit amet createdirectory creates directory pointed by path void createdirectory path path, optional boolean makeparents, optional pathsuccesscallback? successcallback, optional errorcallback? errorcallback ; since 5 0 successful directory creation invokes successcallback function, if specified in case of failure errorcallback function is invoked, if specified the errorcallback is launched with these error types ioerror, if any of the input/output error occurs notfounderror, if directory given in path does not exist and makeparents is set to false privilege level public privilege http //tizen org/privilege/filesystem write parameters path path to directory to create makeparents [optional] flag indicating whether lacking directories should be created for instance, if method is invoked with parameter path equal to documents/path/to/dir and there is no directory "path" in "documents" virtual root, directories "path", "to" and "dir" will be created by default, makeparents is equal to true successcallback [optional] [nullable] callback function to be invoked on success errorcallback [optional] [nullable] callback function to be invoked when an error occurs exceptions webapiexception with error type invalidvalueserror, if the path is invalid with error type securityerror, if the application does not have the privilege to call this method or the application does not have privilege to access the storage for more information, see storage privileges with error type typemismatcherror, if any of the input parameters is not compatible with the expected type for that parameter code example function errorcallback error { console log "an error occurred, during directory creation " + error message ; } function successcallback path { console log "the directory has been created, path to created directory " + path ; /* directory can now be accessed */ } try { tizen filesystem createdirectory "documents/foo_dir/bar_dir", true, successcallback, errorcallback ; } catch error { console log "directory cannot be created " + error message ; } output example the directory has been created, path to created directory documents/foo_dir/bar_dir deletefile deletes file pointed by path void deletefile path path, optional pathsuccesscallback? successcallback, optional errorcallback? errorcallback ; since 5 0 successful file deletion invokes successcallback function, if specified in case of failure errorcallback function is invoked, if specified the errorcallback is launched with these error types ioerror, if any of the input/output error occurs notfounderror, if the path does not point to an existing file privilege level public privilege http //tizen org/privilege/filesystem write parameters path path to file successcallback [optional] [nullable] callback function to be invoked on success errorcallback [optional] [nullable] callback function to be invoked when an error occurs exceptions webapiexception with error type invalidvalueserror, if the path is invalid with error type securityerror, if the application does not have the privilege to call this method or the application does not have privilege to access the storage for more information, see storage privileges with error type typemismatcherror, if any of the input parameters is not compatible with the expected type for that parameter code example function errorcallback error { console log "an error occurred, during file deletion " + error message ; } function successcallback path { console log "the file has been deleted, path to the parent of deleted file " + path ; } try { tizen filesystem deletefile "documents/foo", successcallback, errorcallback ; } catch error { console log "file cannot be deleted " + error message ; } output example the file has been deleted, path to the parent of deleted file documents deletedirectory deletes directory or directory tree under the current directory pointed by path void deletedirectory path path, optional boolean recursive, optional pathsuccesscallback? successcallback, optional errorcallback? errorcallback ; since 5 0 successful directory deletion invokes successcallback function, if specified in case of failure errorcallback function is invoked, if specified the errorcallback is launched with these error types ioerror, if a directory is not empty and recursive is equal to false notfounderror, if the path does not point to an existing directory privilege level public privilege http //tizen org/privilege/filesystem write parameters path a path to directory recursive [optional] flag indicating whether the deletion is recursive or not if recursive is set to true the method will delete content of a given directory recursively otherwise, the method succeeds only if the directory is empty, on other cases errorcallback is called by default, recursive is equal to true successcallback [optional] [nullable] callback function to be invoked on success errorcallback [optional] [nullable] callback function to be invoked when an error occurs exceptions webapiexception with error type invalidvalueserror, if the path is invalid with error type securityerror, if the application does not have the privilege to call this method or the application does not have privilege to access the storage for more information, see storage privileges with error type typemismatcherror, if any of the input parameters is not compatible with the expected type for that parameter code example function errorcallback error { console log "an error occurred, during directory deletion " + error message ; } function successcallback path { console log "the directory has been deleted, path to the parent of deleted directory " + path ; } try { tizen filesystem deletedirectory "documents/foo_dir", true, successcallback, errorcallback ; } catch error { console log "directory cannot be deleted " + error message ; } output example the directory has been deleted, path to the parent of deleted directory documents copyfile copies file from location pointed by sourcepath to destinationpath void copyfile path sourcepath, path destinationpath, optional boolean overwrite, optional pathsuccesscallback? successcallback, optional errorcallback? errorcallback ; since 5 0 successful file copying invokes successcallback function, if specified in case of failure errorcallback function is invoked, if specified the errorcallback is launched with these error types ioerror, if any of the input/output error occurs notfounderror, if the sourcepath does not point to an existing file privilege level public privilege http //tizen org/privilege/filesystem read privilege http //tizen org/privilege/filesystem write parameters sourcepath path to file destinationpath path for copied file the path must consist of path to an existing directory concatenated with '/' and the name of new file overwrite [optional] flag indicating whether to overwrite an existing file if overwrite is set to true and file pointed by destinationpath already exists, the method will overwrite the file otherwise, if a file with conflicting name already exists errorcallback is called by default, overwrite is equal to false successcallback [optional] [nullable] callback function to be invoked on success errorcallback [optional] [nullable] callback function to be invoked when an error occurs exceptions webapiexception with error type invalidvalueserror, if any of the input parameters contains an invalid value for example, the sourcepath or the destinationpath is invalid with error type securityerror, if the application does not have the privilege to call this method or the application does not have privilege to access the storage for more information, see storage privileges with error type typemismatcherror, if any of the input parameters is not compatible with the expected type for that parameter code example function errorcallback error { console log "an error occurred, during copy operation " + error message ; } function successcallback path { console log "the file has been copied, path to copied file " + path ; /* file copy can now be accessed */ } try { tizen filesystem copyfile "documents/foo", "documents/bar", true, successcallback, errorcallback ; } catch error { console log "copy operation cannot be performed " + error message ; } output example the file has been copied, path to copied file documents/bar copydirectory recursively copies directory pointed by sourcepath to destinationpath void copydirectory path sourcepath, path destinationpath, optional boolean overwrite, optional pathsuccesscallback? successcallback, optional errorcallback? errorcallback ; since 5 0 the method merges content of the directory pointed by sourcepath with content of the directory pointed by destinationpath, if exists if the directory pointed by destinationpath does not exist, it is created successful directory copying invokes successcallback function, if specified in case of failure errorcallback function is invoked, if specified the errorcallback is launched with these error types ioerror, if a directory with conflicting name already exists and overwrite is equal to false or any of the input/output error occurs notfounderror, if the sourcepath does not point to an existing directory privilege level public privilege http //tizen org/privilege/filesystem read privilege http //tizen org/privilege/filesystem write parameters sourcepath path to directory destinationpath path for copied directory the path must consist of path to an existing directory concatenated with '/' and the name of destination directory overwrite [optional] flag indicating whether to overwrite existing content if overwrite is equal to true, the file or directory with conflicting name will be overwritten otherwise, errorcallback will be called with ioerror by default, overwrite is equal to false successcallback [optional] [nullable] callback function to be invoked on success errorcallback [optional] [nullable] callback function to be invoked when an error occurs exceptions webapiexception with error type invalidvalueserror, if any of the input parameters contains an invalid value for example, the sourcepath or the destinationpath is invalid with error type securityerror, if the application does not have the privilege to call this method or the application does not have privilege to access the storage for more information, see storage privileges with error type typemismatcherror, if any of the input parameters is not compatible with the expected type for that parameter code example function errorcallback error { console log "an error occurred, during copy operation " + error message ; } function successcallback path { console log "the directory has been copied, path to copied directory " + path ; /* directory copy can now be accessed */ } try { tizen filesystem copydirectory "documents/foo_dir", "documents/bar_dir", true, successcallback, errorcallback ; } catch error { console log "copy operation cannot be performed " + error message ; } output example the directory has been copied, path to copied directory documents/bar_dir code example function errorcallback error { console log "an error occurred " + error message ; } function createfoodircallback { tizen filesystem createdirectory "documents/foo_dir/dir_2", true, createfilecallback, errorcallback ; } function listcallback files, path { console log "found inside " + path + " directory " ; for var i = 0; i < files length; i++ { console log files[i] ; } } function successcallback path { console log "the directory has been created and copied, path to directory " + path ; /* directory 'documents/bar_dir' content is as below */ /* documents/bar_dir/dir_1 */ /* documents/bar_dir/dir_2 */ /* documents/bar_dir/dir_1/file */ tizen filesystem listdirectory "documents/bar_dir", listcallback, errorcallback ; tizen filesystem listdirectory "documents/bar_dir/dir_1", listcallback, errorcallback ; } function createfilecallback { tizen filesystem openfile "documents/foo_dir/dir_1/file", "w" close ; try { tizen filesystem copydirectory "documents/foo_dir", "documents/bar_dir", true, successcallback, errorcallback ; } catch error { console log "copy operation cannot be performed " + error message ; } } tizen filesystem createdirectory "documents/foo_dir/dir_1", true, createfoodircallback, errorcallback ; output example the directory has been created and copied, path to directory documents/bar_dir found inside documents/bar_dir directory dir_1 dir_2 found inside documents/bar_dir/dir_1 directory file movefile moves file pointed by sourcepath to destinationpath void movefile path sourcepath, path destinationpath, optional boolean overwrite, optional pathsuccesscallback? successcallback, optional errorcallback? errorcallback ; since 5 0 successful file moving invokes successcallback function, if specified in case of failure errorcallback function is invoked, if specified the errorcallback is launched with these error types ioerror, if a file with conflicting name already exists and overwrite is equal to false or any of the input/output error occurs notfounderror, if the sourcepath or destinationpath does not point to an existing file or directory privilege level public privilege http //tizen org/privilege/filesystem read privilege http //tizen org/privilege/filesystem write parameters sourcepath path to file destinationpath a destination directory path to move the file to overwrite [optional] flag indicating whether to overwrite an existing file if overwrite is set to true and file with the same name in destinationpath already exists, the method will overwrite the file otherwise, if a file with conflicting name already exists errorcallback is called by default, overwrite is equal to false successcallback [optional] [nullable] callback function to be invoked on success errorcallback [optional] [nullable] callback function to be invoked when an error occurs exceptions webapiexception with error type invalidvalueserror, if any of the input parameters contains an invalid value for example, the sourcepath or the destinationpath is invalid with error type securityerror, if the application does not have the privilege to call this method or the application does not have privilege to access the storage for more information, see storage privileges with error type typemismatcherror, if any of the input parameters is not compatible with the expected type for that parameter code example function errorcallback error { console log "an error occurred, during move operation " + error message ; } function successcallback path { console log "the file has been moved, path to moved file " + path ; /* moved file can now be accessed */ } try { tizen filesystem movefile "documents/foo", "documents/foo_dir/", false, successcallback, errorcallback ; } catch error { console log "move operation cannot be performed " + error message ; } output example the file has been moved, path to moved file documents/foo_dir/foo movedirectory recursively moves directory pointed by sourcepath to destinationpath void movedirectory path sourcepath, path destinationpath, optional boolean overwrite, optional pathsuccesscallback? successcallback, optional errorcallback? errorcallback ; since 5 0 the method merges content of the directory pointed by sourcepath with content of the directory with the same name in destinationpath, if exists successful directory moving invokes successcallback function, if specified in case of failure errorcallback function is invoked, if specified the errorcallback is launched with these error types ioerror, if a directory with conflicting name already exists and overwrite is equal to false or any of the input/output error occurs notfounderror, if the sourcepath or destinationpath does not point to an existing directory privilege level public privilege http //tizen org/privilege/filesystem read privilege http //tizen org/privilege/filesystem write parameters sourcepath a path to directory destinationpath a destination directory path to move the directory to overwrite [optional] flag indicating whether to overwrite existing content if overwrite is equal to true, the file or directory with conflicting name will be overwritten otherwise, errorcallback will be called with ioerror by default, overwrite is equal to false successcallback [optional] [nullable] callback function to be invoked on success errorcallback [optional] [nullable] callback function to be invoked when an error occurs exceptions webapiexception with error type invalidvalueserror, if any of the input parameters contains an invalid value for example, the sourcepath or the destinationpath is invalid with error type securityerror, if the application does not have the privilege to call this method or the application does not have privilege to access the storage for more information, see storage privileges with error type typemismatcherror, if any of the input parameters is not compatible with the expected type for that parameter code example function errorcallback error { console log "an error occurred, during move operation " + error message ; } function successcallback path { console log "the directory has been moved, path to moved directory " + path ; /* moved directory can now be accessed */ } try { tizen filesystem movedirectory "documents/foo_dir", "documents/bar_dir/", false, successcallback, errorcallback ; } catch error { console log "move operation cannot be performed " + error message ; } output example the directory has been moved, path to moved directory documents/bar_dir/foo_dir rename renames file or directory located in path to name newname void rename path path, domstring newname, optional pathsuccesscallback? successcallback, optional errorcallback? errorcallback ; since 5 0 successful renaming invokes successcallback function, if specified in case of failure errorcallback function is invoked, if specified the errorcallback is launched with these error types ioerror, if a file or a directory with conflicting name already exists or any of the input/output error occurs notfounderror, if the path does not point to an existing file or directory privilege level public privilege http //tizen org/privilege/filesystem write parameters path a path to directory or file newname a new name of directory or file successcallback [optional] [nullable] callback function to be invoked on success errorcallback [optional] [nullable] callback function to be invoked when an error occurs exceptions webapiexception with error type invalidvalueserror, if the path or newname is invalid with error type securityerror, if the application does not have the privilege to call this method or the application does not have privilege to access the storage for more information, see storage privileges with error type typemismatcherror, if any of the input parameters is not compatible with the expected type for that parameter code example function errorcallback error { console log "an error occurred, during rename operation " + error message ; } function successcallback path { console log "the file has been renamed, path to renamed file or directory " + path ; } try { tizen filesystem rename "documents/foo", "bar", successcallback, errorcallback ; } catch error { console log "rename operation cannot be performed " + error message ; } output example the file has been renamed, path to renamed file or directory documents/bar listdirectory lists directory content located in path void listdirectory path path, listdirectorysuccesscallback successcallback, optional errorcallback? errorcallback, optional filefilter? filter ; since 5 0 successful listing of directory content invokes successcallback function, if specified in case of failure errorcallback function is invoked, if specified if the filter is passed and contains valid values, only those directories or files in the directory that match the filter criteria specified in the filefilter interface are returned in successcallback method if the filter is null or undefined the implementation must return the full list of files in the directory if the directory does not contain any files or directories, or the filter criteria do not match with any files or directories, the successcallback is invoked with an empty array the errorcallback is launched with these error types ioerror, if any of the input/output error occurs notfounderror, if the path does not point to an existing directory privilege level public privilege http //tizen org/privilege/filesystem read parameters path a path to directory successcallback callback function to be invoked on success errorcallback [optional] [nullable] callback function to be invoked when an error occurs filter [optional] [nullable] filter to restrict the listed files exceptions webapiexception with error type invalidvalueserror, if any of the input parameters contains an invalid value for example, the path is invalid with error type securityerror, if the application does not have the privilege to call this method or the application does not have privilege to access the storage for more information, see storage privileges with error type typemismatcherror, if any of the input parameters is not compatible with the expected type for that parameter code example function errorcallback error { console log "an error occurred, during directory listing " + error message ; } function successcallback files, path { console log "found directories in " + path + " directory " ; for var i = 0; i < files length; i++ { console log files[i] ; } } try { var start = new date "jan 01 2018 00 00 00" ; tizen filesystem listdirectory "documents/", successcallback, errorcallback, {name "foo_%", isdirectory true, startmodified start} ; } catch error { console log "directory listing cannot be performed " + error message ; } output example found directories in documents/ directory foo_dir_c foo_dir_b foo_dir_d foo_dir_a touri converts path to file uri domstring touri path path ; since 5 0 remark the function does not check if path exists in filesystem parameters path a path to a file or a directory return value domstring file uri for given path exceptions webapiexception with error type invalidvalueserror, if the path is invalid code example var path1 = tizen filesystem touri "documents/directory/file ext" ; var path2 = tizen filesystem touri "/opt/usr/home/owner/content/documents/directory/file ext" ; var path3 = tizen filesystem touri "file ///opt/usr/home/owner/content/documents/directory/file ext" ; /* all above paths point to the same file */ console log path1 ; console log path2 ; console log path3 ; var mmcpath = tizen filesystem touri "removable_sda1/documents/directory/file" ; console log mmcpath ; output example file ///opt/usr/home/owner/content/documents/directory/file ext file ///opt/usr/home/owner/content/documents/directory/file ext file ///opt/usr/home/owner/content/documents/directory/file ext file ///opt/media/usbdrivea1/documents/directory/file isfile checks if given path points to a file boolean isfile path path ; since 5 0 privilege level public privilege http //tizen org/privilege/filesystem read parameters path a path to be tested return value boolean true if path points to a file, false otherwise exceptions webapiexception with error type invalidvalueserror, if the path is invalid with error type ioerror, if any of the input/output error occurs with error type notfounderror, if the path does not point to an existing file or directory with error type securityerror, if the application does not have the privilege to call this method or the application does not have privilege to access the storage for more information, see storage privileges code example console log "documents/foo_file is " + tizen filesystem isfile "documents/foo_file" ? "file" "directory" ; output example documents/foo_file is file isdirectory checks if given path points to a directory boolean isdirectory path path ; since 5 0 privilege level public privilege http //tizen org/privilege/filesystem read parameters path a path to be tested return value boolean true if path points to a directory, false otherwise exceptions webapiexception with error type invalidvalueserror, if the path is invalid with error type ioerror, if any of the input/output error occurs with error type notfounderror, if the path does not point to an existing file or directory with error type securityerror, if the application does not have the privilege to call this method or the application does not have privilege to access the storage for more information, see storage privileges code example console log "documents/foo_dir is " + tizen filesystem isdirectory "documents/foo_dir" ? "directory" "file" ; output example documents/foo_dir is directory pathexists checks if given path exists boolean pathexists path path ; since 5 0 privilege level public privilege http //tizen org/privilege/filesystem read parameters path a path to be tested return value boolean true if path points to a existing element, false otherwise exceptions webapiexception with error type invalidvalueserror, if the path is invalid with error type ioerror, if input/output error occurs with error type securityerror, if the application does not have the privilege to call this method or the application does not have privilege to access the storage for more information, see storage privileges code example console log "documents/foo " + tizen filesystem pathexists "documents/foo" ? "exists" "does not exist" ; output example documents/foo does not exist getdirname returns path to directory for given path domstring getdirname domstring path ; since 5 0 strips trailing '/', then breaks path into two components by last path separator, returns first component remark this function does not check if path is valid or exists in filesystem parameters path path to file or directory return value domstring path to directory for given path code example console log tizen filesystem getdirname "/home/owner/media/documents" ; output example "/home/owner/media" resolve resolves a location to a file handle after validating it deprecated since 5 0 void resolve domstring location, filesuccesscallback onsuccess, optional errorcallback? onerror, optional filemode? mode ; since 1 0 a location can contain a virtual path like "documents/some_file txt" or a file uri like "file ///my_strange_path/some_file png" a location is not allowed to contain the " " or " " directory entries inside its value the list of root locations that must be supported by a compliant implementation are documents - the default folder in which text documents such as pdf, doc are stored by default in a device for example, in some platforms it corresponds to the "my documents" folder images - the default folder in which still images, like pictures in formats including jpg, gif, png, etc , are stored in the device by default for example, in some platforms it corresponds to the "my images" folder music - the default folder in which sound clips in formats including mp3, aac, etc are stored in the device by default for example, in some platforms it corresponds to the "my music" folder videos - the default folder in which video clips in formats including avi, mp4, etc are stored in the device by default for example, in some platforms it corresponds to the "my videos" folder downloads - the default folder in which downloaded files from sources including browser, e-mail client, etc are stored by default in the device for example, in some platforms it corresponds to the "downloads" folder ringtones - the default folder in which ringtones such as mp3, etc are stored in the device camera - the default folder in which pictures and videos taken by a device are stored wgt-package - the read-only folder to which the content of a widget file is extracted wgt-private - the private folder in which a widget stores its information this folder must be accessible only to the same widget and other widgets or applications must not be able to access the stored information wgt-private-tmp - temporary, the private folder in which a widget can store data that is available during a widget execution cycle content of this folder can be removed from this directory when the widget is closed or the web runtime is restarted this folder must be accessible only to the same widget and other widgets or applications must not be able to access it the mode parameter specifies whether the resulting file object has read-only access r access , read and write access rw access , append access a access , or write access w access to the root location containing directory tree permission for the requested access is obtained from the security framework once the resulting file object has access, access is inherited by any other file objects that are derived from this instance without any further reference to the security framework, as noted in descriptions of certain methods of file the errorcallback is launched with these error types invalidvalueserror - if any of the input parameters contains an invalid value for example, the mode is w for the read-only virtual roots wgt-package and ringtones notfounderror - if the location input argument does not correspond to a valid location unknownerror - if any other error occurs privilege level public privilege http //tizen org/privilege/filesystem read remark camera location is supported since tizen 2 3 if a device does not support camera, notsupportederror will be thrown parameters location location to resolve that can be a virtual path or file uri onsuccess callback method to be invoked when the location has been successfully resolved, passing the newly created file object onerror [optional] [nullable] callback method to be invoked when an error has occurred mode [optional] [nullable] optional value to indicate the file access mode on all files and directories that can be reached from the file object passed to onsuccess default value of this parameter is rw if absent or null exceptions webapiexception with error type notsupportederror, if this feature is not supported e g in the case of "camera" virtual path if the device does not support camera , or if mode has been set to "rwo", which was introduced in tizen version 5 0 with error type securityerror, if the application does not have the privilege to call this method or the application does not have privilege to access the storage for more information, see storage privileges with error type typemismatcherror, if any of the input parameters is not compatible with the expected type for that parameter code example tizen filesystem resolve "images", function dir { console log "images are stored in " + dir path ; }, function e { console log "error " + e message ; }, "r" ; getstorage gets information about a storage based on its label for example "mythumbdrive", "internalflash" void getstorage domstring label, filesystemstoragesuccesscallback onsuccess, optional errorcallback? onerror ; since 1 0 the onsuccess method receives the data structure as an input argument containing additional information about the drive the errorcallback is launched with these error types invalidvalueserror - if any of the input parameters contains an invalid value notfounderror - if no drive was found with the given label unknownerror - if any other error occurs privilege level public privilege http //tizen org/privilege/filesystem read parameters label storage label onsuccess callback method to be invoked when the list of storages is available, passing the storage list to the callback onerror [optional] [nullable] callback method to be invoked when an error occurs exceptions webapiexception with error type typemismatcherror, if the input parameter is not compatible with the expected type for that parameter with error type securityerror, if the application does not have the privilege to call this method for more information, see storage privileges code example function onstorage storage { /* do something */ } function onstorageerror e { console log "storage not found " + e message ; } tizen filesystem getstorage "music", onstorage, onstorageerror ; liststorages lists the available storages both internal and external on a device the onsuccess method receives a list of the data structures as input argument containing additional information about each drive found it can get storages that would have a label named as "internal0", virtual roots images, documents, , "removable1", "removable2" "removable1" label is used to resolve sdcard and "removable2" label is used to resolve usb host, if supported the vfat filesystem used to sdcard filesystem widely is not case-sensitive if you want to handle the file on sdcard, you need to consider case-sensitive filenames are regarded as same name void liststorages filesystemstoragearraysuccesscallback onsuccess, optional errorcallback? onerror ; since 1 0 labels can differ depending on platform implementation the errorcallback is launched with these error types invalidvalueserror - if any of the input parameters contains an invalid value unknownerror - if any other error occurs privilege level public privilege http //tizen org/privilege/filesystem read parameters onsuccess callback method to be invoked when a list of storage is available and passing the storage list to the callback onerror [optional] [nullable] callback method to be invoked when an error occurs exceptions webapiexception with error type typemismatcherror, if the input parameter is not compatible with the expected type for that parameter with error type securityerror, if the application does not have the privilege to call this method for more information, see storage privileges code example function alertforcorruptedremovabledrives storages { for var i = 0; i < storages length; i++ { if storages[i] type != "external" continue; if storages[i] state == "unmountable" console log "external drive " + storages[i] label + " is corrupted " ; } } tizen filesystem liststorages alertforcorruptedremovabledrives ; addstoragestatechangelistener adds a listener to subscribe to notifications when a change in storage state occurs long addstoragestatechangelistener filesystemstoragesuccesscallback onsuccess, optional errorcallback? onerror ; since 1 0 the most common usage for this method is to watch for any additions and removals of external storages when executed, it returns a subscription identifier that identifies the watch operation after returning the identifier, the watch operation is started asynchronously the onsuccess method will be invoked every time a storage state changes if the attempt fails, the onerror if present will be invoked with the relevant error type the watch operation must continue until the removestoragestatechangelistener method is called with the corresponding subscription identifier privilege level public privilege http //tizen org/privilege/filesystem write parameters onsuccess callback method to be invoked when any change is made to storage state onerror [optional] [nullable] callback method to be invoked when an error occurs during the watch process return value long subscription identifier exceptions webapiexception with error type securityerror, if the application does not have the privilege to call this method for more information, see storage privileges with error type typemismatcherror, if any input parameter is not compatible with the expected type for that parameter with error type unknownerror, if any other error occurs code example var watchid; function onstoragestatechanged storage { if storage state == "mounted" console log "storage " + storage label + " was added!" ; } watchid = tizen filesystem addstoragestatechangelistener onstoragestatechanged ; removestoragestatechangelistener removes a listener to unsubscribe from a storage watch operation void removestoragestatechangelistener long watchid ; since 1 0 if the watchid argument is valid and corresponds to a subscription already in place, the watch process will be stopped and no further callbacks will be invoked otherwise, the method call has no effect privilege level public privilege http //tizen org/privilege/filesystem write parameters watchid subscription identifier exceptions webapiexception with error type securityerror, if the application does not have the privilege to call this method for more information, see storage privileges with error type unknownerror, if any other error occurs code example var watchid; function onstoragestatechanged storage { if storage state == "mounted" console log "storage " + storage label + " was added!" ; tizen filesystem removestoragestatechangelistener watchid ; } watchid = tizen filesystem addstoragestatechangelistener onstoragestatechanged ; 2 3 filesystemstorage the filesystemstorage interface gives additional information about a storage, such as if the device is mounted, if it is a removable drive or not, or the device's name [nointerfaceobject] interface filesystemstorage { readonly attribute domstring label; readonly attribute filesystemstoragetype type; readonly attribute filesystemstoragestate state; }; since 1 0 to retrieve the mount point, the resolve method should be used using the label as argument attributes readonly domstring label the storage name this attribute is used as an input for methods such as getstorage and also used as location parameter for file resolve and filesystemmanager resolve since 1 0 readonly filesystemstoragetype type the storage type as internal or external since 1 0 readonly filesystemstoragestate state the storage state as mounted or not since 1 0 2 4 filehandle object representing file, used for read/write operations [nointerfaceobject] interface filehandle { readonly attribute path path; long long seek long long offset, optional baseseekposition whence raises webapiexception ; void seeknonblocking long long offset, optional seeksuccesscallback? onsuccess, optional errorcallback? onerror, optional baseseekposition whence raises webapiexception ; domstring readstring optional long long? count, optional domstring inputencoding raises webapiexception ; void readstringnonblocking optional readstringsuccesscallback? onsuccess, optional errorcallback? onerror, optional long long count, optional domstring inputencoding raises webapiexception ; long long writestring domstring inputstring, optional domstring outputencoding raises webapiexception ; void writestringnonblocking domstring inputstring, optional writestringsuccesscallback? onsuccess, optional errorcallback? onerror, optional domstring outputencoding raises webapiexception ; blob readblob optional long long size raises webapiexception ; void readblobnonblocking optional readblobsuccesscallback? onsuccess, optional errorcallback? onerror, optional long long? size raises webapiexception ; void writeblob blob blob raises webapiexception ; void writeblobnonblocking blob blob, optional successcallback? onsuccess, optional errorcallback? onerror raises webapiexception ; uint8array readdata optional long long size raises webapiexception ; void readdatanonblocking optional readdatasuccesscallback? onsuccess, optional errorcallback? onerror, optional long long? size raises webapiexception ; void writedata uint8array data raises webapiexception ; void writedatanonblocking uint8array data, optional successcallback? onsuccess, optional errorcallback? onerror raises webapiexception ; void flush raises webapiexception ; void flushnonblocking optional successcallback? onsuccess, optional errorcallback? onerror raises webapiexception ; void sync raises webapiexception ; void syncnonblocking optional successcallback? onsuccess, optional errorcallback? onerror raises webapiexception ; void close raises webapiexception ; void closenonblocking optional successcallback? onsuccess, optional errorcallback? onerror raises webapiexception ; }; since 5 0 each read or write operation moves position in file forwards to the end of read/written data there is an underlying file position's indicator remark due to multibyte utf-8 encoding, if current file's pointer does not point to beginning of multibyte sequence see utf-16, emoji , using seek combined with utf-8 readstring will result in string starting from valid character incomplete byte sequence at the beginning may be omitted be aware about using seek and write methods together it can result in writing in the middle of multibyte sequence, which can lead to file with corrupted content attributes readonly path path path, as passed to openfile since 5 0 methods seek sets position indicator in file stream to offset long long seek long long offset, optional baseseekposition whence ; since 5 0 note, that current position indicator value, can be obtained by calling seek 0, "current" parameters offset number of bytes to shift the position relative to whence whence [optional] determines position in file stream to which offset is added default value "begin" return value long long file position indicator exceptions webapiexception with error type ioerror, if seek fails or any error related to file handle occurs with error type typemismatcherror, if the input parameter is not compatible with the expected type for that parameter code example var datatowrite = new uint8array [11, 21, 31, 44, 55, 66, 71, 81, 91] ; /* opening file for write - file is created if not exists, */ /* otherwise existing file is truncated */ var filehandlewrite = tizen filesystem openfile "documents/file", "w" ; filehandlewrite writedata datatowrite ; filehandlewrite close ; console log "data has been written" ; /* opening file for read - this code assumes that there is */ /* a file named "file" in documents directory */ var filehandleread = tizen filesystem openfile "documents/file", "r" ; var firstthreebytes = filehandleread readdata 3 ; console log "first three bytes " + firstthreebytes ; var position = filehandleread seek -3, "end" ; /* moving to position three bytes to the end of file */ var lastthreebytes = filehandleread readdata 3 ; console log "last three bytes " + lastthreebytes ; filehandleread seek 3, "begin" ; /* moving to position at third byte */ var bytesbetween = filehandleread readdata position - 3 ; console log "bytes between " + bytesbetween ; filehandleread close ; output example data has been written first three bytes 11,21,31 last three bytes 71,81,91 bytes between 44,55,66 seeknonblocking sets position indicator in file stream to offset void seeknonblocking long long offset, optional seeksuccesscallback? onsuccess, optional errorcallback? onerror, optional baseseekposition whence ; since 5 0 successful seek operation invokes onsuccess function, if specified in case of failure onerror function is invoked, if specified the errorcallback is launched with these error types ioerror, if any error related to file handle occurs note, that current position indicator value, can be obtained in seeksuccesscallback by calling seeknonblocking 0, "current" seeknonblocking is executed in background and does not block further instructions parameters offset number of bytes to shift the position relative to whence onsuccess [optional] [nullable] callback function to be invoked on success onerror [optional] [nullable] callback function to be invoked when an error occurs whence [optional] determines position in file stream to which offset is added default value "begin" exceptions webapiexception with error type typemismatcherror, if the input parameter is not compatible with the expected type for that parameter code example /* opening file for write - file is created if not exists, */ /* otherwise existing file is truncated */ var filehandlewrite = tizen filesystem openfile "documents/file", "w" ; filehandlewrite writestringnonblocking "lorem ipsum dolor sit amet ", function bytescount { console log "number of bytes written " + bytescount ; }, function error { console log error ; } ; /* moving to position 3 bytes to the end of file to alter three dots " " */ filehandlewrite seeknonblocking -3, function new_position { console log "moved to position " + new_position ; }, function error { console log error ; }, "end" ; filehandlewrite writestringnonblocking ", consectetur adipiscing elit ", function bytescount { console log "number of bytes written " + bytescount ; }, function error { console log error ; } ; /* moving to position 3 bytes to the end of file to alter three dots " " */ filehandlewrite seeknonblocking -3, function new_position { console log "moved to position " + new_position ; }, function error { console log error ; }, "end" ; filehandlewrite writestringnonblocking ", sed do eiusmod ", function bytescount { console log "number of bytes written " + bytescount ; }, function error { console log error ; } ; filehandlewrite closenonblocking function { console log "file handle closed" ; }, function error { console log error ; } ; /* opening file for read - this code assumes that there is */ /* a file named "file" in documents directory */ var filehandleread = tizen filesystem openfile "documents/file", "r" ; /* readstringsuccesscallback should be executed */ filehandleread readstringnonblocking function output { console log "file content " + output ; }, function error { console log error ; } ; filehandleread closenonblocking function { console log "file handle closed" ; }, function error { console log error ; } ; output example number of bytes written 29 moved to position 26 number of bytes written 32 moved to position 55 number of bytes written 19 file handle closed file content lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod file handle closed readstring reads file content as string domstring readstring optional long long? count, optional domstring inputencoding ; since 5 0 sets file handle position indicator at the end of read data reads given number of characters remark resulting string can have length larger than count, due to possible utf-16 surrogate pairs in it string length in javascript is counted in utf-16 encoding, so for example string containing one emoji surrogate of two utf-16 character will have length of two parameters count [optional] [nullable] number of characters to read from file if none is given, method attempts to read whole file inputencoding [optional] default value "utf-8" encoding to use for read operation on the file, at least the following encodings must be supported "utf-8" default encoding "iso-8859-1" latin-1 encoding return value domstring string with data read from file exceptions webapiexception with error type invalidvalueserror if given count exceeds maximum value supported by the device with error type ioerror, if read fails or any error related to file handle occurs with error type notsupportederror, if the given encoding is not supported with error type typemismatcherror, if the input parameter is not compatible with the expected type for that parameter code example /* opening file for write - file is created if not exists, */ /* otherwise existing file is truncated */ var filehandlewrite = tizen filesystem openfile "documents/file", "w" ; console log "file opened for writing" ; filehandlewrite writestring "lorem ipsum dolor sit amet " ; console log "string has been written to the file" ; filehandlewrite close ; /* opening file for read - this code assumes that there is */ /* a file named "file" in documents directory */ var filehandleread = tizen filesystem openfile "documents/file", "r" ; console log "file opened for reading" ; var filecontent = filehandleread readstring ; console log "file content " + filecontent ; filehandleread close ; output example file opened for writing string has been written to the file file opened for reading file content lorem ipsum dolor sit amet readstringnonblocking reads file content as string void readstringnonblocking optional readstringsuccesscallback? onsuccess, optional errorcallback? onerror, optional long long count, optional domstring inputencoding ; since 5 0 reads given number of characters sets file handle position indicator at the end of read data readstringnonblocking is executed in background and does not block further instructions successful read operation invokes onsuccess function, if specified in case of failure onerror function is invoked, if specified the errorcallback is launched with these error types ioerror, if read fails or any error related to file handle occurs parameters onsuccess [optional] [nullable] callback function with read data from file to be invoked on success onerror [optional] [nullable] callback function to be invoked when an error occurs count [optional] number of characters to read from file if none is given, method attempts to read whole file inputencoding [optional] default value "utf-8" encoding to use for read operation on the file, at least the following encodings must be supported "utf-8" default encoding "iso-8859-1" latin-1 encoding exceptions webapiexception with error type invalidvalueserror if given count exceeds maximum value supported by the device with error type notsupportederror, if the given encoding is not supported with error type typemismatcherror, if the input parameter is not compatible with the expected type for that parameter code example /* opening file for write - file is created if not exists, */ /* otherwise existing file is truncated */ var filehandlewrite = tizen filesystem openfile "documents/file", "w" ; console log "file opened for writing" ; filehandlewrite writestringnonblocking "lorem ipsum dolor sit amet ", function bytescount { console log "number of bytes written " + bytescount ; }, function error { console log error ; } ; filehandlewrite closenonblocking function { console log "file handle closed" ; }, function error { console log error ; } ; /* opening file for read - below code assumes that there is */ /* a file named "file" in documents directory */ var filehandleread = tizen filesystem openfile "documents/file", "r" ; /* readstringsuccesscallback should be executed */ filehandleread readstringnonblocking function output { console log "file content " + output ; }, function error { console log error ; } ; filehandleread closenonblocking function { console log "file handle closed" ; }, function error { console log error ; } ; output example file opened for writing number of bytes written 29 file handle closed file content lorem ipsum dolor sit amet file handle closed writestring writes inputstring content to a file long long writestring domstring inputstring, optional domstring outputencoding ; since 5 0 sets file handle position indicator at the end of written data parameters inputstring string value to be written to a file outputencoding [optional] default value utf-8 encoding to use for write operation on the file, at least the following encodings must be supported "utf-8" default encoding "iso-8859-1" latin-1 encoding return value long long number of bytes written can be more than inputstring length for multibyte encodings and will never be less exceptions webapiexception with error type ioerror, if input/output error occurs with error type notsupportederror, if the given encoding is not supported code example /* opening file for write - file is created if not exists, */ /* otherwise existing file is truncated */ var filehandlewrite = tizen filesystem openfile "documents/file", "w" ; console log "file opened for writing" ; filehandlewrite writestring "lorem ipsum dolor sit amet " ; console log "string has been written to the file" ; filehandlewrite close ; /* opening file for read - this code assumes that there is */ /* a file named "file" in documents directory */ var filehandleread = tizen filesystem openfile "documents/file", "r" ; console log "file opened for reading" ; var filecontent = filehandleread readstring ; console log "file content " + filecontent ; filehandleread close ; output example file opened for writing string has been written to the file file opened for reading file content lorem ipsum dolor sit amet writestringnonblocking writes inputstring content to a file void writestringnonblocking domstring inputstring, optional writestringsuccesscallback? onsuccess, optional errorcallback? onerror, optional domstring outputencoding ; since 5 0 sets file handle position indicator at the end of written data writestringnonblocking is executed in background and does not block further instructions successful write operation invokes successcallback function, if specified in case of failure onerror function is invoked, if specified the errorcallback is launched with these error types ioerror, if write fails or any error related to file handle occurs parameters inputstring string value to be written to a file onsuccess [optional] [nullable] callback function with a number of bytes written as parameter to be invoked on success onerror [optional] [nullable] callback function to be invoked when an error occurs outputencoding [optional] default value "utf-8" encoding to use for write operation on the file, at least the following encodings must be supported "utf-8" default encoding "iso-8859-1" latin-1 encoding exceptions webapiexception with error type notsupportederror, if the given encoding is not supported with error type typemismatcherror, if the input parameter is not compatible with the expected type for that parameter code example /* opening file for write - file is created if not exists, */ /* otherwise existing file is truncated */ var filehandlewrite = tizen filesystem openfile "documents/file", "w" ; filehandlewrite writestringnonblocking "lorem ipsum dolor sit amet ", function bytescount { console log "number of bytes written " + bytescount ; }, function error { console log error ; } ; filehandlewrite closenonblocking function { console log "file handle closed" ; }, function error { console log error ; } ; /* opening file for read - below code assumes that there is */ /* a file named "file" in documents directory */ var filehandleread = tizen filesystem openfile "documents/file", "r" ; /* readstringsuccesscallback should be executed */ filehandleread readstringnonblocking function output { console log "file content " + output ; }, function error { console log error ; } ; filehandleread closenonblocking function { console log "file handle closed" ; }, function error { console log error ; } ; output example number of bytes written 29 file handle closed file content lorem ipsum dolor sit amet file handle closed readblob reads file content as blob blob readblob optional long long size ; since 5 0 sets file handle position indicator at the end of read data parameters size [optional] size in bytes of data to read from file if none is given, method attempts to read whole file return value blob blob object with file content exceptions webapiexception with error type invalidvalueserror if given size exceeds maximum value supported by the device with error type ioerror, if read fails or any error related to file handle occurs code example /* opening file for write - file is created if not exists, */ /* otherwise existing file is truncated */ var filehandlewrite = tizen filesystem openfile "documents/file", "w" ; var b = new blob ["lorem ipsum dolor sit amet "], {type "text/plain"} ; filehandlewrite writeblob b ; filehandlewrite close ; console log "blob content has been written to file" ; /* opening file for read - this code assumes that there is */ /* a file named "file" in documents directory */ var filehandleread = tizen filesystem openfile "documents/file", "r" ; var filecontentinblob = filehandleread readblob ; filehandleread close ; const reader = new filereader ; /* event fires after the blob has been read/loaded */ reader onloadend = function content { const text = content srcelement result; console log "file content " + text ; }; /* starts reading the blob as text */ reader readastext filecontentinblob ; output example blob content has been written to file file content lorem ipsum dolor sit amet readblobnonblocking reads file content as blob void readblobnonblocking optional readblobsuccesscallback? onsuccess, optional errorcallback? onerror, optional long long? size ; since 5 0 sets file handle position indicator at the end of read data readblobnonblocking is executed in background and does not block further instructions successful read operation invokes onsuccess function, if specified in case of failure onerror function is invoked, if specified the errorcallback is launched with these error types ioerror, if read fails or any error related to file handle occurs parameters onsuccess [optional] [nullable] callback function with blob object to be invoked on success onerror [optional] [nullable] callback function to be invoked when an error occurs size [optional] [nullable] size in bytes of data to read from file if none is given, method attempts to read whole file exceptions webapiexception with error type invalidvalueserror if given size exceeds maximum value supported by the device with error type typemismatcherror, if the input parameter is not compatible with the expected type for that parameter code example /* opening file for write - file is created if not exists, */ /* otherwise existing file is truncated */ var filehandlewrite = tizen filesystem openfile "documents/file", "w" ; var b = new blob ["lorem ipsum dolor sit amet "], {type "text/plain"} ; filehandlewrite writeblobnonblocking b, function { console log "blob content has been written to file" ; }, function error { console log error ; } ; filehandlewrite closenonblocking function { console log "file handle closed" ; }, function error { console log error ; } ; /* opening file for read - this code assumes that there is */ /* a file named "file" in documents directory */ var filehandleread = tizen filesystem openfile "documents/file", "r" ; /* creation of a reader capable of extracting blob content */ const reader = new filereader ; /* event fires after the blob has been read/loaded */ reader onloadend = function content { const text = content srcelement result; console log "file content " + text ; }; function readblobcallback filecontentinblob { reader readastext filecontentinblob ; } /* readblobcallback should be executed */ filehandleread readblobnonblocking readblobcallback, function error { console log error ; } ; filehandleread closenonblocking function { console log "file handle closed" ; }, function error { console log error ; } ; output example blob content has been written to file file handle closed file handle closed file content lorem ipsum dolor sit amet writeblob writes blob to file void writeblob blob blob ; since 5 0 sets file handle position indicator at the end of written data parameters blob object of type blob, which content will be written to a file exceptions webapiexception with error type ioerror, if write fails or any error related to file handle occurs with error type typemismatcherror, if the input parameter is not compatible with the expected type for that parameter code example /* opening file for write - file is created if not exists, */ /* otherwise existing file is truncated */ var filehandlewrite = tizen filesystem openfile "documents/file", "w" ; var b = new blob ["lorem ipsum dolor sit amet "], {type "text/plain"} ; filehandlewrite writeblob b ; filehandlewrite close ; console log "blob content has been written to file" ; /* opening file for read - this code assumes that there is */ /* a file named "file" in documents directory */ var filehandleread = tizen filesystem openfile "documents/file", "r" ; var filecontentinblob = filehandleread readblob ; filehandleread close ; console log "file content has been read from file" ; const reader = new filereader ; /* event fires after the blob has been read/loaded */ reader onloadend = function content { const text = content srcelement result; console log "file content " + text ; }; /* starts reading the blob as text */ reader readastext filecontentinblob ; output example blob content has been written to file file content has been read from file file content lorem ipsum dolor sit amet writeblobnonblocking writes blob to file void writeblobnonblocking blob blob, optional successcallback? onsuccess, optional errorcallback? onerror ; since 5 0 sets file handle position indicator at the end of written data writeblobnonblocking is executed in background and does not block further instructions successful write operation invokes onsuccess function, if specified in case of failure onerror function is invoked, if specified the errorcallback is launched with these error types ioerror, if write fails or any error related to file handle occurs parameters blob object of type blob, which content will be written to a file onsuccess [optional] [nullable] callback function to be invoked on success onerror [optional] [nullable] callback function to be invoked when an error occurs exceptions webapiexception with error type typemismatcherror, if the input parameter is not compatible with the expected type for that parameter code example /* opening file for write - file is created if not exists, */ /* otherwise existing file is truncated */ var filehandlewrite = tizen filesystem openfile "documents/file", "w" ; var b = new blob ["lorem ipsum dolor sit amet "], {type "text/plain"} ; filehandlewrite writeblobnonblocking b, function { console log "blob content has been written to file" ; }, function error { console log error ; } ; filehandlewrite closenonblocking function { console log "file handle closed" ; }, function error { console log error ; } ; /* opening file for read - this code assumes that there is */ /* a file named "file" in documents directory */ var filehandleread = tizen filesystem openfile "documents/file", "r" ; /* creation of a reader capable of extracting blob content */ const reader = new filereader ; /* event fires after the blob has been read/loaded */ reader onloadend = function content { const text = content srcelement result; console log "file content " + text ; }; function readblobcallback filecontentinblob { reader readastext filecontentinblob ; } /* readblobcallback should be executed */ filehandleread readblobnonblocking readblobcallback ; filehandleread closenonblocking function { console log "file handle closed" ; }, function error { console log error ; } ; output example blob content has been written to file file handle closed file handle closed file content lorem ipsum dolor sit amet readdata reads file content as binary data uint8array readdata optional long long size ; since 5 0 can be used in combination with atob or btoa functions sets file handle position indicator at the end of read data parameters size [optional] size in bytes of data to read from file if none is given, method attempts to read whole file return value uint8array read data as uint8array exceptions webapiexception with error type invalidvalueserror if given size exceeds maximum value supported by the device with error type ioerror, if read fails or any error related to file handle occurs code example var datatowrite = new uint8array [11, 21, 31, 71, 81, 91] ; /* opening file for write - file is created if not exists, */ /* otherwise existing file is truncated */ var filehandlewrite = tizen filesystem openfile "documents/file", "w" ; filehandlewrite writedata datatowrite ; filehandlewrite close ; console log "data has been written" ; /* opening file for read - below code assumes that there is */ /* a file named "file" in documents directory */ var filehandleread = tizen filesystem openfile "documents/file", "r" ; var filecontentinuint8array = filehandleread readdata ; filehandleread close ; console log "data read from file " + filecontentinuint8array ; output example data has been written data read from file 11,21,31,71,81,91 readdatanonblocking reads file content as binary data void readdatanonblocking optional readdatasuccesscallback? onsuccess, optional errorcallback? onerror, optional long long? size ; since 5 0 can be used in combination with atob or btoa functions sets file handle position indicator at the end of read data readdatanonblocking is executed in background and does not block further instructions successful read operation invokes onsuccess function, if specified in case of failure onerror function is invoked, if specified the errorcallback is launched with these error types ioerror, if read fails or any error related to file handle occurs parameters onsuccess [optional] [nullable] callback function with read data from file to be invoked on success onerror [optional] [nullable] callback function to be invoked when an error occurs size [optional] [nullable] size in bytes of data to read from file if none is given, method attempts to read whole file exceptions webapiexception with error type invalidvalueserror if given size exceeds maximum value supported by the device with error type typemismatcherror, if the input parameter is not compatible with the expected type for that parameter code example var datatowrite = new uint8array [11, 21, 31, 71, 81, 91] ; /* opening file for write - file is created if not exists, */ /* otherwise existing file is truncated */ var filehandlewrite = tizen filesystem openfile "documents/file", "w" ; filehandlewrite writedatanonblocking datatowrite, function dataread { console log "write done" ; }, function error { console log error ; } ; filehandlewrite closenonblocking function { console log "file handle closed" ; }, function error { console log error ; } ; /* opening file for read - below code assumes that there is */ /* a file named "file" in documents directory */ var filehandleread = tizen filesystem openfile "documents/file", "r" ; filehandleread readdatanonblocking function dataread { console log "data read from file " + dataread ; }, function error { console log error ; } ; filehandleread closenonblocking function { console log "file handle closed" ; }, function error { console log error ; } ; output example write done file handle closed data read from file 11,21,31,71,81,91 file handle closed writedata writes binary data to file void writedata uint8array data ; since 5 0 can be used in combination with atob or btoa functions sets file handle position indicator at the end of written data parameters data an array of type uint8array, which content will be written to file as binary data exceptions webapiexception with error type ioerror, if write fails or any error related to file handle occurs with error type typemismatcherror, if the input parameter is not compatible with the expected type for that parameter code example var datatowrite = new uint8array [11, 21, 31, 71, 81, 91] ; /* opening file for write - file is created if not exists, */ /* otherwise existing file is truncated */ var filehandlewrite = tizen filesystem openfile "documents/file", "w" ; filehandlewrite writedata datatowrite ; filehandlewrite close ; console log "data has been written" ; /* opening file for read - below code assumes that there is */ /* a file named "file" in documents directory */ var filehandleread = tizen filesystem openfile "documents/file", "r" ; var filecontentinuint8array = filehandleread readdata ; filehandleread close ; console log "data read from file " + filecontentinuint8array ; output example data has been written data read from file 11,21,31,71,81,91 writedatanonblocking writes binary data to file void writedatanonblocking uint8array data, optional successcallback? onsuccess, optional errorcallback? onerror ; since 5 0 can be used in combination with atob or btoa functions sets file handle position indicator at the end of written data writedatanonblocking is executed in background and does not block further instructions successful write operation invokes onsuccess function, if specified in case of failure onerror function is invoked, if specified the errorcallback is launched with these error types ioerror, if write fails or any error related to file handle occurs parameters data an array of type uint8array, which content will be written to file as binary data onsuccess [optional] [nullable] callback function to be invoked on success onerror [optional] [nullable] callback function to be invoked when an error occurs exceptions webapiexception with error type typemismatcherror, if the input parameter is not compatible with the expected type for that parameter code example var datatowrite = new uint8array [11, 21, 31, 71, 81, 91] ; /* opening file for write - file is created if not exists, */ /* otherwise existing file is truncated */ var filehandlewrite = tizen filesystem openfile "documents/file", "w" ; filehandlewrite writedatanonblocking datatowrite, function dataread { console log "write done" ; }, function error { console log error ; } ; filehandlewrite closenonblocking function { console log "file handle closed" ; }, function error { console log error ; } ; /* opening file for read - below code assumes that there is */ /* a file named "file" in documents directory */ var filehandleread = tizen filesystem openfile "documents/file", "r" ; filehandleread readdatanonblocking function dataread { console log "data read from file " + dataread ; }, function error { console log error ; } ; filehandleread closenonblocking function { console log "file handle closed" ; }, function error { console log error ; } ; output example write done file handle closed data read from file 11,21,31,71,81,91 file handle closed flush flushes data void flush ; since 5 0 for file handles with permission to write, flush writes any changes made to file content to underlying buffer flush does not ensure that data is written on storage device, it only synchronizes ram with file descriptor to ensure storage synchronization use sync, close or their asynchronous equivalent methods, which guarantee such synchronization exceptions webapiexception with error type ioerror, if flush fails or any error related to file handle occurs code example /* opening file for write - file is created if not exists, */ /* otherwise existing file is truncated */ var filehandlewrite = tizen filesystem openfile "documents/file", "w" ; var filehandleread = tizen filesystem openfile "documents/file", "r" ; filehandlewrite writestring "lorem ipsum dolor sit amet " ; console log "data has been written to file" ; /* calling flush ensures that content has been written to file descriptor and can be read by any */ /* process */ filehandlewrite flush ; console log "data has been flushed to system file buffer and now can be read" ; var filecontent = filehandleread readstring ; console log "read data " + filecontent ; filehandlewrite close ; filehandleread close ; output example data has been written to file data has been flushed to system file buffer and now can be read read data lorem ipsum dolor sit amet flushnonblocking flushes data void flushnonblocking optional successcallback? onsuccess, optional errorcallback? onerror ; since 5 0 for file handles with permission to write, flush writes any changes made to file content to underlying buffer flush does not ensure that data is written on storage device, it only synchronizes ram with file descriptor to ensure storage synchronization use sync, close or their asynchronous equivalent methods, which guarantee such synchronization successful flushing invokes onsuccess function, if specified in case of failure onerror function is invoked, if specified the errorcallback is launched with these error types ioerror, if flush fails or any error related to file handle occurs this method is asynchronous its execution will occur in background and after all previously commissioned background jobs will finish parameters onsuccess [optional] [nullable] callback function to be invoked on success onerror [optional] [nullable] callback function to be invoked when an error occurs exceptions webapiexception with error type typemismatcherror, if the input parameter is not compatible with the expected type for that parameter code example /* opening file for write - file is created if not exists, */ /* otherwise existing file is truncated */ var filehandlewrite = tizen filesystem openfile "documents/file", "w" ; filehandlewrite writestringnonblocking "lorem ipsum dolor sit amet ", function bytescount { console log "number of bytes written " + bytescount ; }, function error { console log error ; } ; /* calling flushnonblocking ensures that content will be written to file descriptor */ /* and can be read by any process */ filehandlewrite flushnonblocking function { console log "data has been flushed to system file buffer and now can be read" ; }, function error { console log error ; } ; /* opening file for read - this code assumes that there is */ /* a file named "file" in documents directory */ var filehandleread = tizen filesystem openfile "documents/file", "r" ; filehandleread readstringnonblocking function output { console log "file content " + output ; }, function error { console log error ; } ; filehandlewrite closenonblocking function { console log "file handle closed" ; }, function error { console log error ; } ; filehandleread closenonblocking function { console log "file handle closed" ; }, function error { console log error ; } ; output example number of bytes written 29 data has been flushed to system file buffer and now can be read file content lorem ipsum dolor sit amet file handle closed file handle closed sync synchronizes data to storage device void sync ; since 5 0 the sync function is intended to force a physical write of data from the buffer cache and to assure that after a system crash or other failure that all data up to the time of the sync call is recorded on the disk exceptions webapiexception with error type ioerror, if sync fails or any error related to file handle occurs code example var datatowrite = new uint8array [11, 21, 31, 71, 81, 91] ; /* opening file for write - file is created if not exists, */ /* otherwise existing file is truncated */ var filehandlewrite = tizen filesystem openfile "documents/file", "w" ; filehandlewrite writedata datatowrite ; /* calling sync forces a physical write of data, so it is safe */ /* even after system crash or power shut down */ filehandlewrite sync ; console log "data has been synced" ; /* close method provides the same functionality as sync and ends access to file */ filehandlewrite close ; output example data has been synced **syncnonblocking ** synchronizes data to storage device void syncnonblocking optional successcallback? onsuccess, optional errorcallback? onerror ; since 5 0 the syncnonblocking function is intended to force a physical write of data from the buffer cache and to assure that after a system crash or other failure that all data up to the time of the syncnonblocking execution is recorded on the disk successful syncing invokes onsuccess function, if specified in case of failure onerror function is invoked, if specified the errorcallback is launched with these error types ioerror, if sync fails or any error related to file handle occurs this method is asynchronous its execution will occur in background and after all previously commissioned background jobs will finish parameters onsuccess [optional] [nullable] callback function to be invoked on success onerror [optional] [nullable] callback function to be invoked when an error occurs exceptions webapiexception with error type typemismatcherror, if the input parameter is not compatible with the expected type for that parameter code example var datatowrite = new uint8array [11, 21, 31, 71, 81, 91] ; /* opening file for write - file is created if not exists, */ /* otherwise existing file is truncated */ var filehandlewrite = tizen filesystem openfile "documents/file", "w" ; filehandlewrite writedatanonblocking datatowrite, function dataread { console log "write done" ; }, function error { console log error ; } ; /* calling syncnonblocking will force a physical write of data, so it will be safe */ /* even after system crash or power shut down */ filehandlewrite syncnonblocking function { console log "data has been synced" ; }, function error { console log error ; } ; /* close method provides the same functionality as sync and ends access to file */ filehandlewrite closenonblocking function { console log "file handle closed" ; }, function error { console log error ; } ; output example write done data has been synced file handle closed close closes file handle void close ; since 5 0 closes the given file stream closing file guarantees writing changes made to filehandle to the storage device further operations on this file handle are not allowed remark this method is synchronous if any asynchronous method was called before close, close will block further instructions until all background jobs finish execution note, that if file handle functions are put into any callbacks and this callback was not yet called, synchronous close will wait only for already ordered background jobs to finish, preventing successful execution of any further operations on closed file handle exceptions webapiexception with error type ioerror, if close fails or any error related to file handle occurs code example /* opening file for write - file is created if not exists, */ /* otherwise existing file is truncated */ var filehandlewrite = tizen filesystem openfile "documents/file", "w" ; filehandlewrite writestring "lorem ipsum dolor sit amet " ; filehandlewrite close ; console log "string has been written to the file" ; /* opening file for read - this code assumes that there is */ /* a file named "file" in documents directory */ var filehandleread = tizen filesystem openfile "documents/file", "r" ; var positionoffileend = filehandleread seek 0, "end" ; console log "seek operation done position of file end " + positionoffileend ; filehandleread close ; console log "file is now closed" ; output example string has been written to the file seek operation done position of file end 29 file is now closed closenonblocking closes file handle void closenonblocking optional successcallback? onsuccess, optional errorcallback? onerror ; since 5 0 closes the given file stream closing file guarantees writing changes made to filehandle to the storage device further operations on this file handle are not allowed successful closing invokes onsuccess function, if specified in case of failure onerror function is invoked, if specified the errorcallback is launched with these error types ioerror, if close fails or any error related to file handle occurs this method is asynchronous its execution will occur in background and after all previously commissioned background jobs will finish parameters onsuccess [optional] [nullable] callback function to be invoked on success onerror [optional] [nullable] callback function to be invoked when an error occurs exceptions webapiexception with error type typemismatcherror, if the input parameter is not compatible with the expected type for that parameter code example /* opening file for write - file is created if not exists, */ /* otherwise existing file is truncated */ var filehandlewrite = tizen filesystem openfile "documents/file", "w" ; filehandlewrite writestringnonblocking "lorem ipsum dolor sit amet ", function bytescount { console log "number of bytes written " + bytescount ; }, function error { console log error ; } ; filehandlewrite closenonblocking function { console log "file handle closed" ; }, function error { console log error ; } ; /* opening file for read - this code assumes that there is */ /* a file named "file" in documents directory */ var filehandleread = tizen filesystem openfile "documents/file", "r" ; var positionoffileend = filehandleread seeknonblocking 0, function new_position { console log "moved to position " + new_position ; }, function error { console log error ; }, "end" ; filehandleread closenonblocking function { console log "file handle closed" ; }, function error { console log error ; } ; output example number of bytes written 29 file handle closed moved to position 29 file handle closed 2 5 file the file interface represents the file abstraction in use deprecated since 5 0 [nointerfaceobject] interface file { readonly attribute file? parent; readonly attribute boolean readonly; readonly attribute boolean isfile; readonly attribute boolean isdirectory; readonly attribute date? created; readonly attribute date? modified; readonly attribute domstring path; readonly attribute domstring name; readonly attribute domstring fullpath; readonly attribute unsigned long long filesize; readonly attribute long length; domstring touri raises webapiexception ; void listfiles filearraysuccesscallback onsuccess, optional errorcallback? onerror, optional filefilter? filter raises webapiexception ; void openstream filemode mode, filestreamsuccesscallback onsuccess, optional errorcallback? onerror, optional domstring? encoding raises webapiexception ; void readastext filestringsuccesscallback onsuccess, optional errorcallback? onerror, optional domstring? encoding raises webapiexception ; void copyto domstring originfilepath, domstring destinationfilepath, boolean overwrite, optional successcallback? onsuccess, optional errorcallback? onerror raises webapiexception ; void moveto domstring originfilepath, domstring destinationfilepath, boolean overwrite, optional successcallback? onsuccess, optional errorcallback? onerror raises webapiexception ; file createdirectory domstring dirpath raises webapiexception ; file createfile domstring relativefilepath raises webapiexception ; file resolve domstring filepath raises webapiexception ; void deletedirectory domstring directorypath, boolean recursive, optional successcallback? onsuccess, optional errorcallback? onerror raises webapiexception ; void deletefile domstring filepath, optional successcallback? onsuccess, optional errorcallback? onerror raises webapiexception ; }; since 1 0 the file object permissions for the file object location and tree rooted at that location depend upon the mode defined in the resolve method when a file object creates a child file object, the new file object inherits its access rights from the parent object without any reference to the security framework, as noted in certain methods of file a file handle represents either a file or a directory for a file, the isfile attribute is set to true for a directory, the isdirectory attribute is set to true a file can be opened for both read and write operations, using a filestream handle a list of files and sub-directories can be obtained from a directory and a resolve method exists to resolve files or sub-directories more conveniently than processing directory listings a file handle representing a file can be opened for i/o operations, such as reading and writing a file handle representing a directory can be used for listing all files and directories rooted as the file handle location code example function onsuccess files { for var i = 0; i < files length; i++ { /* alerts each name of dir's content */ console log files[i] name ; } } function onerror error { console log "the error " + error message + " occurred when listing the files in the selected folder" ; } /* list directory content */ dir listfiles onsuccess, onerror ; attributes readonly file parent [nullable] the parent directory handle deprecated since 5 0 this attribute is set to null if there is no parent directory this also implies that this directory represents a root location since 1 0 code example /* list directory content */ dir listfiles onsuccess, onerror ; function onsuccess files { for var i = 0; i < files length; i++ { /* prints the file parent, must contain the */ /* same value for all the files in the loop */ console log "all the files should have the same parent " + files[i] parent ; } } function onerror error { console log "the error " + error message + " occurred when listing the files in the selected folder" ; } readonly boolean readonly the file/directory access state in the filesystem deprecated since 5 0 this attribute is set to true - if object has read-only access at its location false - if object has write access at its location this attribute represents the actual state of a file or directory in the filesystem its value is not affected by the mode used in filesystemmanager resolve that was used to create the file object from which this file object was obtained since 1 0 code example /* lists directory content */ dir listfiles onsuccess, onerror ; function onsuccess files { for var i = 0; i < files length; i++ { if files[i] readonly console log "cannot write to file " + files[i] name ; else console log "can write to file " + files[i] name ; } } function onerror error { console log "the error " + error message + " occurred when listing the files in the selected folder" ; } readonly boolean isfile the flag indicating whether it is a file deprecated since 5 0 this attribute can have the following values true if this handle is a file false if this handle is a directory since 1 0 readonly boolean isdirectory the flag indicating whether it is a directory deprecated since 5 0 this attribute can have the following values true if this handle is a directory false if this handle is a file since 1 0 readonly date created [nullable] the timestamp when a file is first created in the filesystem deprecated since 5 0 this timestamp is equivalent to the timestamp when a call to createfile succeeds if the platform does not support this attribute, it will be null it is unspecified and platform-dependent if the creation timestamp changes when a file is moved since 1 0 readonly date modified [nullable] the timestamp when the most recent modification is made to a file, usually when the last write operation succeeds deprecated since 5 0 opening a file for reading does not change the modification timestamp if the platform does not support this attribute, it will be null it is unspecified and platform-dependent if the modified timestamp changes when a file is moved since 1 0 code example console log file modified ; /* displays the modification timestamp */ readonly domstring path the path of a file after excluding its file name deprecated since 5 0 it begins with the name of the root containing the file, followed by the path, including the directory containing the file, but excluding the file name except in some special cases of the file representing the root itself, the last character is always "/" for example, if a file is located at music/ramones/volume1/rockawaybeach mp3, the path is music/ramones/volume1/ for example, if a directory is located at music/ramones/volume1, the path is music/ramones/ for the virtual roots, the path is same as the name of the virtual root for example, if the root is music, then the path is music if the root is documents, then the path is documents since 1 0 code example console log file path ; /* must be music/ if the file is music/foo mp3 */ readonly domstring name the file name after excluding the root name and any path components deprecated since 5 0 this is the name of this file, excluding the root name and any other path components for example, if a file is located at music/ramones/volume1/rockawaybeach mp3, the name is "rockawaybeach mp3" for example, if a directory is located at music/ramones/volume1, the name is be "volume1" for the special case of the root itself, the name is an empty string since 1 0 code example /* must be foo mp3 if the file path is music/foo mp3 */ console log file name ; readonly domstring fullpath the full path of a file deprecated since 5 0 it begins with the name of the root containing the file, and including the name of the file or directory itself for instance, if the rockawaybeach mp3 file is located at music/ramones/volume1/, then the fullpath is music/ramones/volume1/rockawaybeach mp3 for a directory, if the volume1 directory is located at music/ramones/, then the fullpath is music/ramones/volume1 for the special case of the root itself, if the root is music, then the fullpath is music the fullpath is always equal to path + name since 1 0 code example /* must be music/track1 mp3 if the file is music/track1 mp3 */ console log file fullpath ; readonly unsigned long long filesize the size of this file, in bytes deprecated since 5 0 if an attempt to read this attribute for a directory is made, undefined is returned to retrieve the number of files and directories contained in the directory, use the length attribute since 1 0 code example /* displays the file size */ console log file filesize ; readonly long length the number of files and directories contained in a file handle deprecated since 5 0 if an attempt to read this attribute for a file is made, undefined is returned to retrieve the size of a file, use the filesize attribute since 1 0 code example /* "3" if the directory contains two files and one sub-directory */ console log file length ; methods touri returns a uri for a file to identify an entry such as using it as the src attribute on an html img element the uri has no specific expiration, it should be valid at least as long as the file exists deprecated since 5 0 domstring touri ; since 1 0 if that uri corresponds to any of the public virtual roots that is images, videos, music, documents and downloads the uri must be globally unique and could be used by any widget if that uri corresponds to a file located in any a widget's private areas such as wgt-package, wgt-private, wgt-private-tmp , the generated uri must be unique for that file and for the widget making the request such as including some derived from the widget id in the uri these uris must not be accessible to other widgets, apart from the one invoking this method privilege level public privilege http //tizen org/privilege/filesystem read return value domstring uri that identifies the file or null if an error occurs exceptions webapiexception with error type securityerror, if the application does not have the privilege to call this method for more information, see storage privileges with error type unknownerror, if any other error occurred code example tizen filesystem resolve "music/ramones/rockawaybeach mp3", function file { var audio = new audio file touri ; audio play ; console log file touri ; } ; listfiles lists all files in a directory deprecated since 5 0 void listfiles filearraysuccesscallback onsuccess, optional errorcallback? onerror, optional filefilter? filter ; since 1 0 the list of files is passed as a file[] in onsuccess and contains directories and files however, the directories " " and " " must not be returned each file object that is part of the array must inherit all the access rights that is, one of the values in filemode from the file object in which this method is invoked if the filter is passed and contains valid values, only those directories and files in the directory that match the filter criteria specified in the filefilter interface must be returned in the onsuccess method if no filter is passed, the filter is null or undefined, or the filter contains invalid values, the implementation must return the full list of files in the directory if the directory does not contain any files or directories, or the filter criteria do not match any files or directories, the onsuccess is invoked with an empty array the errorcallback is launched with these error types ioerror - if the operation is launched on a file not a directory invalidvalueserror - if any of the input parameters contain an invalid value unknownerror - if any other error occurs privilege level public privilege http //tizen org/privilege/filesystem read parameters onsuccess callback method to be invoked when the list operation has been successfully completed onerror [optional] [nullable] callback method to be invoked when an error has occurred filter [optional] [nullable] criteria to restrict the listed files exceptions webapiexception with error type typemismatcherror, if the input parameter is not compatible with the expected type for that parameter with error type securityerror, if the application does not have the privilege to call this method for more information, see storage privileges code example function onsuccess files { console log "there are " + files length + " in the selected folder" ; } function onerror error { console log "the error " + error message + " occurred when listing the files in the selected folder" ; } tizen filesystem resolve "documents", function dir { dir listfiles onsuccess, onerror ; }, function e { console log "error " + e message ; }, "r" ; openstream opens the file in the given mode supporting a specified encoding deprecated since 5 0 void openstream filemode mode, filestreamsuccesscallback onsuccess, optional errorcallback? onerror, optional domstring? encoding ; since 1 0 this operation is performed asynchronously if the file is opened successfully, the onsuccess method is invoked with a filestream that can be used for reading and writing the file, depending on the mode the returned filestream instance includes a file pointer, which represents the current position in the file the file pointer, by default, is at the start of the file, except in the case of opening a file in append "a" mode, in which case the file pointer points to the end of the file the errorcallback is launched with these error types invalidvalueserror - if any of the input parameters contains an invalid value ioerror - the operation is launched on a directory not a file , the file is not valid or it does not exist unknownerror - if any other error occurs privilege level public privilege http //tizen org/privilege/filesystem read parameters mode mode in which the file is opened "r" for reading "a" for appending "w" for [over]writing "rw" for reading and writing onsuccess callback method to be invoked when a file has been opened onerror [optional] [nullable] callback method to be invoked when an error has occurred encoding [optional] [nullable] encoding to use for read/write operations on the file, at least the following encodings must be supported "utf-8" default encoding "iso-8859-1" latin1 encoding if no encoding is passed by the developer, then the default platform encoding must be used exceptions webapiexception with error type typemismatcherror, if the input parameter is not compatible with the expected type for that parameter with error type securityerror, if the application does not have the privilege to call this method or the application does not have privilege to access the storage for more information, see storage privileges code example var documentsdir; function onsuccess files { for var i = 0; i < files length; i++ { console log "file name is " + files[i] name ; /* displays file name */ } var testfile = documentsdir createfile "test txt" ; if testfile != null { testfile openstream "w", function fs { fs write "helloworld" ; fs close ; }, function e { console log "error " + e message ; }, "utf-8" ; } } function onerror error { console log "the error " + error message + " occurred when listing the files in the selected folder" ; } tizen filesystem resolve "documents", function dir { documentsdir = dir; dir listfiles onsuccess, onerror ; }, function e { console log "error " + e message ; }, "rw" ; readastext reads the content of a file as a domstring deprecated since 5 0 void readastext filestringsuccesscallback onsuccess, optional errorcallback? onerror, optional domstring? encoding ; since 1 0 if the operation is successfully executed, the onsuccess method is invoked and a domstring is passed as input parameter that represents the file content in the format determined by the encoding parameter the errorcallback is launched with these error types invalidvalueserror - if any of the input parameters contains an invalid value ioerror - if the operation is launched on a directory not a file , the file is not valid, or the file does not exist unknownerror - if any other error occurs privilege level public privilege http //tizen org/privilege/filesystem read parameters onsuccess callback method to be invoked when a file has been successfully read onerror [optional] [nullable] callback method to be invoked when an error occurs while reading a file encoding [optional] [nullable] encoding for read/write operations on a file, at least the following encodings must be supported "utf-8" default encoding "iso-8859-1" latin1 encoding if no encoding is passed by the developer, then the default platform encoding must be used exceptions webapiexception with error type typemismatcherror, if the input parameter is not compatible with the expected type for that parameter with error type securityerror, if the application does not have the privilege to call this method for more information, see storage privileges code example var documentsdir; function onsuccess files { for var i = 0; i < files length; i++ { console log "file name is " + files[i] name ; /* displays file name */ if files[i] isdirectory == false { files[i] readastext function str { console log "the file content " + str ; }, function e { console log "error " + e message ; }, "utf-8" ; } } } function onerror error { console log "the error " + error message + " occurred when listing the files in the selected folder" ; } tizen filesystem resolve "documents", function dir { documentsdir = dir; dir listfiles onsuccess, onerror ; }, function e { console log "error " + e message ; }, "rw" ; copyto copies and overwrites if possible and specified a file or a directory from a specified location to another specified location deprecated since 5 0 void copyto domstring originfilepath, domstring destinationfilepath, boolean overwrite, optional successcallback? onsuccess, optional errorcallback? onerror ; since 1 0 the copy of the file or directory identified by the originfilepath parameter must be created in the path passed in the destinationfilepath parameter the file or directory to copy must be under the directory from which the method is invoked, otherwise the operation must not be performed if the copy is performed successfully, the onsuccess method is invoked the errorcallback is launched with these error types invalidvalueserror - if any of the input parameters contains an invalid value notfounderror - if the originfilepath does not correspond to a valid file or destinationpath is not a valid path ioerror - if the file in which the copyto method is invoked is a file and not a directory , originfilepath corresponds to a file or directory in use by another process, overwrite parameter is false and destinationfilepath corresponds to an existing file or directory unknownerror - if any other error occurs privilege level public privilege http //tizen org/privilege/filesystem write parameters originfilepath origin full virtual file or directory path and it must be under the current directory destinationfilepath new full virtual file path or directory path overwrite attribute to determine whether overwriting is allowed or not if set to true, it enforces overwriting an existing file onsuccess [optional] [nullable] callback method to be invoked when the file has been copied onerror [optional] [nullable] callback method to be invoked when an error has occurred exceptions webapiexception with error type typemismatcherror, if the input parameter is not compatible with the expected type for that parameter with error type securityerror, if the application does not have the privilege to call this method or the application does not have privilege to access the storage for more information, see storage privileges code example var documentsdir; function onsuccess files { for var i = 0; i < files length; i++ { if files[i] isdirectory == false { documentsdir copyto files[i] fullpath, "images/backup/" + files[i] name, false, function { console log "file copied" ; } ; } } } function onerror error { console log "the error " + error message + " occurred when listing the files in the selected folder" ; } tizen filesystem resolve "documents", function dir { documentsdir = dir; dir listfiles onsuccess, onerror ; }, function e { console log "error " + e message ; }, "rw" ; moveto moves and overwrites if possible and specified a file or a directory from a specified location to another this operation is different from instantiating copyto and then deleting the original file, as on certain platforms, this operation does not require extra disk space deprecated since 5 0 void moveto domstring originfilepath, domstring destinationfilepath, boolean overwrite, optional successcallback? onsuccess, optional errorcallback? onerror ; since 1 0 the file or directory identified by the originfilepath parameter is moved to the path passed in the destinationfilepath parameter the file to move must be under the directory from which the method is invoked, else the operation can not be performed if the file or directory is moved successfully, the onsuccess method is invoked the errorcallback is launched with these error types invalidvalueserror - if any of the input parameters contains an invalid value notfounderror - if originfilepath does not correspond to a valid file or destinationpath is not a valid path ioerror - if the file in which the moveto method is invoked is a file not a directory , originfilepath corresponds to a file or directory in use by another process, overwrite parameter is false and destinationfilepath corresponds to an existing file or directory unknownerror - if any other error occurs privilege level public privilege http //tizen org/privilege/filesystem write parameters originfilepath origin full virtual file or directory path and it must be under the current directory destinationfilepath new full virtual file path or directory path overwrite flag indicating whether to overwrite an existing file when set to true, the files can be overwritten onsuccess [optional] [nullable] callback method to be invoked when the file has been moved onerror [optional] [nullable] callback method to be invoked when an error has occurred exceptions webapiexception with error type typemismatcherror, if the input parameter is not compatible with the expected type for that parameter with error type securityerror, if the application does not have the privilege to call this method or the application does not have privilege to access the storage for more information, see storage privileges code example var documentsdir; function onsuccess files { for var i = 0; i < files length; i++ { if files[i] isdirectory == false { documentsdir moveto files[i] fullpath, "images/newfolder/" + files[i] name, false, function { console log "file moved" ; } ; } } } function onerror error { console log "the error " + error message + " occurred during listing the files in the selected folder" ; } tizen filesystem resolve "documents", function dir { documentsdir = dir; dir listfiles onsuccess, onerror ; }, function e { console log "error " + e message ; }, "rw" ; createdirectory creates a new directory deprecated since 5 0 file createdirectory domstring dirpath ; since 1 0 a new directory will be created relative to the current directory that this operation is performed on the implementation will attempt to create all necessary sub-directories specified in the dirpath, as well the use of " " or " " in path components is not supported this operation can only be performed on file handles that represent directories that is, isdirectory == true if the directory is successfully created, it will be returned in case the directory cannot be created, an error must be thrown with the appropriate error type privilege level public privilege http //tizen org/privilege/filesystem write parameters dirpath relative directory path and it only contains characters supported by the underlying filesystem return value file file handle of the new directory the new file object has "rw" access rights, as it inherits this from the file object on which the createdirectory method is called exceptions webapiexception with error type ioerror, if the dirpath already exists, if the file in which the createdirectory method is invoked is a file and not a directory with error type invalidvalueserror, if the dirpath does not contain a valid path with error type typemismatcherror, if the input parameter is not compatible with the expected type with error type securityerror, if the application does not have the privilege to call this method or the application does not have privilege to access the storage for more information, see storage privileges with error type unknownerror, if any other error occurs code example var dir; /* directory object obtained from filesystem api */ var newdir = dir createdirectory "newdir" ; var anothernewdir = dir createdirectory "newdir1/subnewdir1" ; createfile creates a empty new file in a specified location that is relative to the directory indicated by current file object's path attribute deprecated since 5 0 file createfile domstring relativefilepath ; since 1 0 the use of " " or " " in path components is not supported this operation can only be performed on file handlers that represent a directory that is, isdirectory == true if the file is successfully created, a file handle must be returned by this method in case the file cannot be created, an error must be thrown with the appropriate error type privilege level public privilege http //tizen org/privilege/filesystem write parameters relativefilepath new file path and it should only contain characters supported by the underlying filesystem return value file file handle for the new empty file the new file object has "rw" access rights, as it inherits this from the file object on which the createfile method is called exceptions webapiexception with error type ioerror, if relativefilepath already exists, if the file in which the createfile method is invoked is a file not a directory with error type invalidvalueserror, if relativefilepath contains an invalid value with error type typemismatcherror, if the input parameter is not compatible with the expected type with error type securityerror, if the application does not have the privilege to call this method or the application does not have privilege to access the storage for more information, see storage privileges with error type unknownerror, if any other error occurs code example var newfile = dir createfile "newfilepath" ; resolve resolves an existing file or directory relative to the current directory this operation is performed on and returns a file handle for it deprecated since 5 0 file resolve domstring filepath ; since 1 0 the filepath is not allowed to contain the " " or " " directory entries inside its value the encoding of file paths is utf-8 privilege level public privilege http //tizen org/privilege/filesystem read parameters filepath relative file path or file uri to resolve return value file file handle of the file the new file object inherits its access rights from the file object on which this resolve method is called exceptions webapiexception with error type typemismatcherror, if the input parameter is not compatible with the expected type for that parameter with error type invalidvalueserror, if the file path contains an invalid value with error type ioerror, if the method is executed in a file object that does not represent a directory that is, isdirectory attribute is false with error type notfounderror, if a file does not exist for the passed file path with error type securityerror, if the application does not have the privilege to call this method for more information, see storage privileges with error type unknownerror, if any other error occurs code example var file; /* resolves helloworld doc file that is located in the */ /* documents root location */ tizen filesystem resolve "documents", function dir { file = dir resolve "helloworld doc" ; }, function e { console log "error " + e message ; }, "rw" ; deletedirectory deletes a specified directory and directory tree if specified deprecated since 5 0 void deletedirectory domstring directorypath, boolean recursive, optional successcallback? onsuccess, optional errorcallback? onerror ; since 1 0 this method attempts to asynchronously delete a directory or directory tree under the current directory if the recursive parameter is set to true, all the directories and files under the specified directory must be deleted if the recursive parameter is set to false, the directory is only deleted if it is empty, otherwise an ioerror error type will be passed in onerror if the deletion is performed successfully, the onsuccess is invoked the errorcallback is launched with these error types invalidvalueserror - if any of the input parameters contains an invalid value notfounderror -if the passed directory does not correspond to a valid directory ioerror - if the file in which the delete method is invoked is a file and not a directory , the directory is in use by another process or the directory is not empty and recursive argument is false this code is also used if a recursive deletion partially fails and any data deleted so far cannot be recovered this may occur due to the lack of filesystem permissions or if any directories or files are already opened by other processes unknownerror - if any other error occurs privilege level public privilege http //tizen org/privilege/filesystem write parameters directorypath full virtual path to the directory to delete must be under the current one recursive flag indicating whether the deletion is recursive or not when set to true recursive deletion is allowed also, this function deletes all data in all subdirectories and so needs to be used with caution onsuccess [optional] [nullable] callback method to be invoked when a directory is successfully deleted onerror [optional] [nullable] callback method to be invoked when an error has occurred exceptions webapiexception with error type typemismatcherror, if the input parameter is not compatible with the expected type for that parameter with error type securityerror, if the application does not have the privilege to call this method or the application does not have privilege to access the storage for more information, see storage privileges code example var documentsdir; function onsuccess files { for var i = 0; i < files length; i++ { if files[i] isdirectory { documentsdir deletedirectory files[i] fullpath, false, function { console log "directory deleted" ; }, function e { console log "error " + e message ; } ; } } } function onerror error { console log "the error " + error message + " occurred when listing the files in the selected folder" ; } tizen filesystem resolve "documents", function dir { documentsdir = dir; dir listfiles onsuccess, onerror ; }, function e { console log "error " + e message ; }, "rw" ; deletefile deletes a specified file this function attempts to asynchronously delete a file under the current directory deprecated since 5 0 void deletefile domstring filepath, optional successcallback? onsuccess, optional errorcallback? onerror ; since 1 0 if the deletion is performed successfully, the onsuccess is invoked the errorcallback is launched with these error types invalidvalueserror - if any of the input parameters contains an invalid value notfounderror - if the file does not correspond to a valid file ioerror - if the file in which the delete method is invoked is a file not a directory , the file is in use by another process, or there is no permission in the file system unknownerror - if any other error occurs privilege level public privilege http //tizen org/privilege/filesystem write parameters filepath full virtual path to the file to delete must be under the current directory onsuccess [optional] [nullable] callback method to be invoked when the file is successfully deleted onerror [optional] [nullable] callback method to be invoked when an error has occurred exceptions webapiexception with error type typemismatcherror, if the input parameter is not compatible with the expected type for that parameter with error type securityerror, if the application does not have the privilege to call this method or the application does not have privilege to access the storage for more information, see storage privileges code example var documentsdir; function onsuccess files { for var i = 0; i < files length; i++ { if !files[i] isdirectory { documentsdir deletefile files[i] fullpath, function { console log "file deleted" ; }, function e { console log "error " + e message ; } ; } } } function onerror error { console log "the error " + error message + " occurred when listing the files in the selected folder" ; } tizen filesystem resolve "documents", function dir { documentsdir = dir; dir listfiles onsuccess, onerror ; }, function e { console log "error " + e message ; }, "rw" ; 2 6 filefilter the dictionary that defines attributes to filter the items returned by the listdirectory method or deprecated listfiles dictionary filefilter { domstring name; boolean isfile; boolean isdirectory; date startmodified; date endmodified; date startcreated; date endcreated; }; since 1 0 when this dictionary is passed to a method, the result-set of the method will only contain file item entries that match the attribute values of the filter a file item only matches the filefilter object if all of the defined filter's attribute values match all of the file item's attributes only matching values other than undefined or null this is similar to a sql's "and" operation an attribute of the file entry matches the filefilter attribute value in accordance with the following rules for filefilter attributes of type domstring, an entry matches this value only if its corresponding attribute is an exact match if the filter contains u+0025 "percent sign" it is interpreted as a wildcard character and "%" matches any string of any length, including no length if wildcards are used, the behavior is similar to the like condition in sql to specify that a "percent sign" character is to be considered literally instead of interpreting it as a wildcard, developers can escape it with the backslash character please, remember that the backslash character has to be escaped itself, to not to be removed from the string - proper escaping of the "percent sign" in javascript string requires preceding it with double backslash "%" the matching is not case sensitive, such as "foo" matches a "foo" or an "f%" filter for file entry attributes of type date, attributes start and end are included to allow filtering of file entries between two supplied dates if either or both of these attributes are specified, the following rules apply a if both start and end dates are specified that is, other than null , a file entry matches the filter if its corresponding attribute is the same as either start or end or between the two supplied dates that is, after start and before end b if only the start attribute contains a value other than null , a file entry matches the filter if its corresponding attribute is later than or equal to the start one c if only the end date contains a value other than null , a file matches the filter if its corresponding attribute is earlier than or equal to the end date dictionary members domstring name the file name attribute filter files that have a name that corresponds with this attribute either exactly or with the specified wildcards match this filtering criteria since 1 0 boolean isfile if true match only files if false do not match files may be undefined since 5 0 boolean isdirectory if true match only directories, if false do not match directories may be undefined since 5 0 date startmodified the file modified attribute filter files with modified date later than this attribute or equal to it match the filtering criteria since 1 0 date endmodified the file modified attribute filter files with modified date earlier than this attribute or equal to it match the filtering criteria since 1 0 date startcreated the file created attribute filter files with created date later than this attribute or equal to it match the filtering criteria since 1 0 date endcreated the file created attribute filter files with created date earlier than this attribute or equal to it match the filtering criteria since 1 0 2 7 filestream the filestream interface represents a handle to a file opened for read and/or write operations read and write operations are performed relative to a position attribute, which is a pointer that represents the current position in the file deprecated since 5 0 [nointerfaceobject] interface filestream { readonly attribute boolean eof; attribute long position; readonly attribute long bytesavailable; void close ; domstring read long charcount raises webapiexception ; octet[] readbytes long bytecount raises webapiexception ; domstring readbase64 long bytecount raises webapiexception ; void write domstring stringdata raises webapiexception ; void writebytes octet[] bytedata raises webapiexception ; void writebase64 domstring base64data raises webapiexception ; }; since 1 0 a series of read/write methods are available that permit both binary and text to be processed once a file stream is closed, any operation attempt made on this stream results in a standard javascript error the read/write operations in this interface do not throw any security exceptions as the access rights are expected to be granted through the initial resolve method or through the openstream method of the file interface therefore, all actions performed on a successfully resolved file and filestream are expected to succeed this avoids successive asynchronous calls and may potentially increase application for a user attributes readonly boolean eof the flag indicating whether the current file pointer is at the end of the file deprecated since 5 0 if set to true, this attribute indicates that the file pointer is at the end of the file if set to false, this attribute indicates that the file pointer is not at the end of the file and so it is anywhere within the file since 1 0 code example if stream eof { /* file has been read completely */ } long position the flag indicating the stream position for reads/writes deprecated since 5 0 the stream position is an offset of bytes from the start of the file stream when invoking an operation that reads or writes from the stream, the operation will take place from the byte defined by this position attribute if the read or write operation is successful, the position of the stream is advanced by the number of bytes read or written if the read/write operation is not successful, the position of the stream is unchanged since 1 0 code example console log stream position ; /* displays current stream position */ /* alters current stream position to the begin of the file, */ /* like seek in c */ stream position = 0; readonly long bytesavailable the number of bytes that are available for reading from the stream deprecated since 5 0 the number of bytes available for reading is the maximum amount of bytes that can be read in the next read operation it corresponds to the number of bytes available after the file pointer denoted by the position attribute -1 if eof is true since 1 0 code example console log stream bytesavailable ; /* displays the available bytes to be read */ methods close closes this filestream deprecated since 5 0 void close ; since 1 0 flushes any pending buffered writes and closes the file always succeeds note that pending writes might not succeed privilege level public privilege http //tizen org/privilege/filesystem read code example stream close ; /* closes this stream, no subsequent access to stream allowed */ read reads the specified number of characters from the position of the file pointer in a filestream and returns the characters as a string the resulting string length might be shorter than charcount if eof is true deprecated since 5 0 domstring read long charcount ; since 1 0 privilege level public privilege http //tizen org/privilege/filesystem read parameters charcount number of characters being read return value domstring array of read characters as a string exceptions webapiexception with error type ioerror, if a read error occurs, such as the bytes in the stream cannot be decoded with the encoding in use with error type typemismatcherror, if the input parameter is not compatible with the expected type for that parameter with error type invalidvalueserror, if any of the input parameters contains an invalid value with error type securityerror, if the application does not have the privilege to call this method for more information, see storage privileges code example var text = stream read file filesize ; stream close ; readbytes reads the specified number of bytes from a filestream deprecated since 5 0 octet[] readbytes long bytecount ; since 1 0 privilege level public privilege http //tizen org/privilege/filesystem read parameters bytecount number of bytes to read return value octet[] result of read bytes as a byte or number array exceptions webapiexception with error type ioerror, if a read error occurs with error type typemismatcherror, if the input parameter is not compatible with the expected type for that parameter with error type invalidvalueserror, if any of the input parameters contains an invalid value with error type securityerror, if the application does not have the privilege to call this method for more information, see storage privileges code example /* reads up to 256 bytes from the stream */ var raw = stream readbytes 256 ; for var i = 0; i < raw length; i++ { /* raw[i] contains the i-th byte of the current data chunk */ } readbase64 reads the specified number of bytes from this filestream, encoding the result in base64 deprecated since 5 0 domstring readbase64 long bytecount ; since 1 0 privilege level public privilege http //tizen org/privilege/filesystem read parameters bytecount number of bytes to read return value domstring array of read characters as base64 encoding string exceptions webapiexception with error type ioerror, if a read error occurs with error type typemismatcherror, if the input parameter is not compatible with the expected type for that parameter with error type invalidvalueserror, if any of the input parameters contains an invalid value with error type securityerror, if the application does not have the privilege to call this method for more information, see storage privileges code example /* reads up to 256 bytes from the stream */ var base64 = stream readbase64 256 ; write writes the specified domstring to a filestream deprecated since 5 0 void write domstring stringdata ; since 1 0 privilege level public privilege http //tizen org/privilege/filesystem write parameters stringdata actual string to write exceptions webapiexception with error type ioerror, if a write error occurs with error type typemismatcherror, if the input parameter is not compatible with the expected type for that parameter with error type securityerror, if the application does not have the privilege to call this method for more information, see storage privileges code example var text = "hello world"; stream write text ; writebytes writes the specified bytes to this filestream deprecated since 5 0 void writebytes octet[] bytedata ; since 1 0 privilege level public privilege http //tizen org/privilege/filesystem write parameters bytedata byte data array being written exceptions webapiexception with error type ioerror, if a write error occurs with error type typemismatcherror, if the input parameter is not compatible with the expected type for that parameter with error type securityerror, if the application does not have the privilege to call this method for more information, see storage privileges code example var bytes = input readbytes 256 ; /* writes the bytes read from input to output */ output writebytes bytes ; writebase64 writes the result to this filestream after converting the specified base64 domstring to bytes deprecated since 5 0 void writebase64 domstring base64data ; since 1 0 privilege level public privilege http //tizen org/privilege/filesystem write parameters base64data the base64 data to written exceptions webapiexception with error type ioerror, if an error occurs during writebase64 with error type invalidvalueserror, if the input parameter contains an invalid value e g the base64data input parameter is not a valid base64 sequence with error type securityerror, if the application does not have the privilege to call this method for more information, see storage privileges code example var base64 = input readbase64 256 ; /* writes the base64 data read from input to output */ output writebase64 base64 ; 2 8 filesuccesscallback the filesuccesscallback interface defines file system success callback with a file object as input argument deprecated since 5 0 [callback=functiononly, nointerfaceobject] interface filesuccesscallback { void onsuccess file file ; }; since 1 0 it is used in asynchronous operations, such as filesystemmanager resolve , copying, moving and deleting files methods onsuccess called when the asynchronous call completes successfully deprecated since 5 0 void onsuccess file file ; since 1 0 parameters file file resulting from the asynchronous call 2 9 filesystemstoragearraysuccesscallback the filesystemstoragearraysuccesscallback callback interface specifies a success callback with an array of filesystemstorage objects as input argument [callback=functiononly, nointerfaceobject] interface filesystemstoragearraysuccesscallback { void onsuccess filesystemstorage[] storages ; }; since 1 0 it is used in asynchronous operations, such as filesystemmanager liststorages methods onsuccess called when the asynchronous call completes successfully void onsuccess filesystemstorage[] storages ; since 1 0 parameters storages list of available storage devices 2 10 filesystemstoragesuccesscallback the filesystemstoragesuccesscallback callback interface specifies a success callback with a filesystemstorage object as input argument [callback=functiononly, nointerfaceobject] interface filesystemstoragesuccesscallback { void onsuccess filesystemstorage storage ; }; since 1 0 it is used in asynchronous operations, such as filesystemmanager getstorage and filesystemmanager addstoragestatechangelistener methods onsuccess called when the asynchronous call completes successfully void onsuccess filesystemstorage storage ; since 1 0 parameters storage storage device structure 2 11 pathsuccesscallback the pathsuccesscallback callback interface specifies a success callback with a path value as input argument [callback=functiononly, nointerfaceobject] interface pathsuccesscallback { void onsuccess path path ; }; since 5 0 it is used in asynchronous operations of the filesystemmanager interface methods onsuccess called when the asynchronous call completes successfully void onsuccess path path ; since 5 0 parameters path path to created or changed resource on the filesystem in case of deletion, path to parent of the deleted resource is given 2 12 seeksuccesscallback the seeksuccesscallback callback interface specifies a success callback with a long long value as input argument [callback=functiononly, nointerfaceobject] interface seeksuccesscallback { void onsuccess long long position ; }; since 5 0 it is used in asynchronous operation filehandle seeknonblocking methods onsuccess called when the asynchronous call completes successfully void onsuccess long long position ; since 5 0 parameters position file position indicator 2 13 readstringsuccesscallback the readstringsuccesscallback callback interface specifies a success callback with a domstring value as input argument [callback=functiononly, nointerfaceobject] interface readstringsuccesscallback { void onsuccess domstring string ; }; since 5 0 it is used in asynchronous operation filehandle readstringnonblocking methods onsuccess called when the asynchronous call completes successfully void onsuccess domstring string ; since 5 0 parameters string string with data read from file 2 14 writestringsuccesscallback the writestringsuccesscallback callback interface specifies a success callback with a long long value as input argument [callback=functiononly, nointerfaceobject] interface writestringsuccesscallback { void onsuccess long long bytescount ; }; since 5 0 it is used in asynchronous operation filehandle writestringnonblocking methods onsuccess called when the asynchronous call completes successfully void onsuccess long long bytescount ; since 5 0 parameters bytescount number of bytes written can be more than inputstring length for multibyte encodings and will never be less 2 15 readblobsuccesscallback the readblobsuccesscallback callback interface specifies a success callback with a blob object as input argument [callback=functiononly, nointerfaceobject] interface readblobsuccesscallback { void onsuccess blob blob ; }; since 5 0 it is used in asynchronous operation filehandle readblobnonblocking methods onsuccess called when the asynchronous call completes successfully void onsuccess blob blob ; since 5 0 parameters blob blob object with file content 2 16 readdatasuccesscallback the readdatasuccesscallback callback interface specifies a success callback with a uint8array value as input argument [callback=functiononly, nointerfaceobject] interface readdatasuccesscallback { void onsuccess uint8array data ; }; since 5 0 it is used in asynchronous operation filehandle readdatanonblocking methods onsuccess called when the asynchronous call completes successfully void onsuccess uint8array data ; since 5 0 parameters data a typedarray with file content 2 17 filestringsuccesscallback the filestringsuccesscallback callback interface specifies a success callback with a domstring object as input argument deprecated since 5 0 [callback=functiononly, nointerfaceobject] interface filestringsuccesscallback { void onsuccess domstring filestr ; }; since 1 0 it is used in asynchronous operation file readastext methods onsuccess called when the asynchronous call completes successfully deprecated since 5 0 void onsuccess domstring filestr ; since 1 0 parameters filestr file represented as a domstring resulting from the asynchronous call 2 18 filestreamsuccesscallback the filestreamsuccesscallback interface specifies a success callback with a filestream object as input argument deprecated since 5 0 [callback=functiononly, nointerfaceobject] interface filestreamsuccesscallback { void onsuccess filestream filestream ; }; since 1 0 it is used in asynchronous operation file openstream methods onsuccess called when the file openstream asynchronous call completes successfully deprecated since 5 0 void onsuccess filestream filestream ; since 1 0 parameters filestream filestream to access file content 2 19 listdirectorysuccesscallback the listdirectorysuccesscallback interface defines success callback for listing methods [callback=functiononly, nointerfaceobject] interface listdirectorysuccesscallback { void onsuccess domstring[] names, path path ; }; since 5 0 this callback interface specifies a success callback with a function taking an array of strings as input argument it is used in asynchronous operation filesystemmanager listdirectory methods onsuccess called when the asynchronous call completes successfully void onsuccess domstring[] names, path path ; since 5 0 parameters names file or directory names resulting from the asynchronous call path path to listed directory 2 20 filearraysuccesscallback the filearraysuccesscallback interface defines file system specific success callback for listing methods deprecated since 5 0 [callback=functiononly, nointerfaceobject] interface filearraysuccesscallback { void onsuccess file[] files ; }; since 1 0 this callback interface specifies a success callback with a function taking an array of file objects as input argument it is used in asynchronous methods, such as file listfiles methods onsuccess called when the asynchronous call completes successfully deprecated since 5 0 void onsuccess file[] files ; since 1 0 parameters files files resulting from the asynchronous call 3 full webidl module filesystem { typedef domstring path; typedef blob blob; enum filemode { "a", "r", "rw", "rwo", "w" }; enum filesystemstoragetype { "internal", "external" }; enum filesystemstoragestate { "mounted", "removed", "unmountable" }; enum baseseekposition { "begin", "current", "end" }; dictionary filefilter { domstring name; boolean isfile; boolean isdirectory; date startmodified; date endmodified; date startcreated; date endcreated; }; tizen implements filesystemmanagerobject; [nointerfaceobject] interface filesystemmanagerobject { readonly attribute filesystemmanager filesystem; }; [nointerfaceobject] interface filesystemmanager { readonly attribute long maxnamelength; readonly attribute long maxpathlength; filehandle openfile path path, filemode openmode, optional boolean makeparents raises webapiexception ; void createdirectory path path, optional boolean makeparents, optional pathsuccesscallback? successcallback, optional errorcallback? errorcallback raises webapiexception ; void deletefile path path, optional pathsuccesscallback? successcallback, optional errorcallback? errorcallback raises webapiexception ; void deletedirectory path path, optional boolean recursive, optional pathsuccesscallback? successcallback, optional errorcallback? errorcallback raises webapiexception ; void copyfile path sourcepath, path destinationpath, optional boolean overwrite, optional pathsuccesscallback? successcallback, optional errorcallback? errorcallback raises webapiexception ; void copydirectory path sourcepath, path destinationpath, optional boolean overwrite, optional pathsuccesscallback? successcallback, optional errorcallback? errorcallback raises webapiexception ; void movefile path sourcepath, path destinationpath, optional boolean overwrite, optional pathsuccesscallback? successcallback, optional errorcallback? errorcallback raises webapiexception ; void movedirectory path sourcepath, path destinationpath, optional boolean overwrite, optional pathsuccesscallback? successcallback, optional errorcallback? errorcallback raises webapiexception ; void rename path path, domstring newname, optional pathsuccesscallback? successcallback, optional errorcallback? errorcallback raises webapiexception ; void listdirectory path path, listdirectorysuccesscallback successcallback, optional errorcallback? errorcallback, optional filefilter? filter raises webapiexception ; domstring touri path path raises webapiexception ; boolean isfile path path raises webapiexception ; boolean isdirectory path path raises webapiexception ; boolean pathexists path path raises webapiexception ; domstring getdirname domstring path ; void getstorage domstring label, filesystemstoragesuccesscallback onsuccess, optional errorcallback? onerror raises webapiexception ; void liststorages filesystemstoragearraysuccesscallback onsuccess, optional errorcallback? onerror raises webapiexception ; long addstoragestatechangelistener filesystemstoragesuccesscallback onsuccess, optional errorcallback? onerror raises webapiexception ; void removestoragestatechangelistener long watchid raises webapiexception ; }; [nointerfaceobject] interface filesystemstorage { readonly attribute domstring label; readonly attribute filesystemstoragetype type; readonly attribute filesystemstoragestate state; }; [nointerfaceobject] interface filehandle { readonly attribute path path; long long seek long long offset, optional baseseekposition whence raises webapiexception ; void seeknonblocking long long offset, optional seeksuccesscallback? onsuccess, optional errorcallback? onerror, optional baseseekposition whence raises webapiexception ; domstring readstring optional long long? count, optional domstring inputencoding raises webapiexception ; void readstringnonblocking optional readstringsuccesscallback? onsuccess, optional errorcallback? onerror, optional long long count, optional domstring inputencoding raises webapiexception ; long long writestring domstring inputstring, optional domstring outputencoding raises webapiexception ; void writestringnonblocking domstring inputstring, optional writestringsuccesscallback? onsuccess, optional errorcallback? onerror, optional domstring outputencoding raises webapiexception ; blob readblob optional long long size raises webapiexception ; void readblobnonblocking optional readblobsuccesscallback? onsuccess, optional errorcallback? onerror, optional long long? size raises webapiexception ; void writeblob blob blob raises webapiexception ; void writeblobnonblocking blob blob, optional successcallback? onsuccess, optional errorcallback? onerror raises webapiexception ; uint8array readdata optional long long size raises webapiexception ; void readdatanonblocking optional readdatasuccesscallback? onsuccess, optional errorcallback? onerror, optional long long? size raises webapiexception ; void writedata uint8array data raises webapiexception ; void writedatanonblocking uint8array data, optional successcallback? onsuccess, optional errorcallback? onerror raises webapiexception ; void flush raises webapiexception ; void flushnonblocking optional successcallback? onsuccess, optional errorcallback? onerror raises webapiexception ; void sync raises webapiexception ; void syncnonblocking optional successcallback? onsuccess, optional errorcallback? onerror raises webapiexception ; void close raises webapiexception ; void closenonblocking optional successcallback? onsuccess, optional errorcallback? onerror raises webapiexception ; }; [callback=functiononly, nointerfaceobject] interface filesystemstoragearraysuccesscallback { void onsuccess filesystemstorage[] storages ; }; [callback=functiononly, nointerfaceobject] interface filesystemstoragesuccesscallback { void onsuccess filesystemstorage storage ; }; [callback=functiononly, nointerfaceobject] interface pathsuccesscallback { void onsuccess path path ; }; [callback=functiononly, nointerfaceobject] interface seeksuccesscallback { void onsuccess long long position ; }; [callback=functiononly, nointerfaceobject] interface readstringsuccesscallback { void onsuccess domstring string ; }; [callback=functiononly, nointerfaceobject] interface writestringsuccesscallback { void onsuccess long long bytescount ; }; [callback=functiononly, nointerfaceobject] interface readblobsuccesscallback { void onsuccess blob blob ; }; [callback=functiononly, nointerfaceobject] interface readdatasuccesscallback { void onsuccess uint8array data ; }; [callback=functiononly, nointerfaceobject] interface listdirectorysuccesscallback { void onsuccess domstring[] names, path path ; }; };