Mobile Web Wearable Web

Filesystem

Tizen enables you to manage the files and directories in the device file system.

The Filesystem API is mandatory for both Tizen mobile and wearable profiles, which means that it is supported in all mobile and wearable devices. All mandatory APIs are supported on the Tizen Emulators.

The Filesystem API provides access to accessible parts of the file system, which are represented as virtual root locations. The virtual roots form a collection of locations that function as a single virtual device file system. The following table lists the supported virtual roots.

Table: Filesystem virtual roots
Virtual root Description
documents Location for storing documents.
downloads Location for storing downloaded items.
images Location for storing images.
music Location for storing audio files.
removable Location for the removable storage.
ringtones Location for ringtones (read-only location).
videos Location for storing videos.
wgt-package Location for storing Web application packages (read-only location).
wgt-private Location for the Web application private storage.
wgt-private-tmp Location for the Web application private temporary storage.

The main features of the Filesystem API include:

  • File storage management

    You can manage different storages on the device with the FileSystemManager interface (in mobile and wearable applications).

    You can retrieve additional information about the storages, including listing available storages and receiving storage change notifications with the listStorages() and addStorageStateChangeListener() methods provided by the FileSystemManager interface.

  • Access to files and directories

    You can access the virtual file system using the FileSystemManager interface.

    To access a file or directory within the virtual file system, you must use the fully qualified path, <root name>/<path>, where <rootname> is the name of the virtual root and <path> is the relative path to the file or directory within the root.

    Note
    When you use a path to access the device file system, make sure that the file path encoding uses the default encoding of the platform.

    To access a file or directory, you must also retrieve a file handle using the resolve() method of the FileSystemManager interface. A file handle is a reference object that points to and represents a file or directory.

    The isFile and isDirectory attributes of the File interface (in mobile and wearable applications) identify the type of the object: for example, for a file, the isFile attribute is set to true and the isDirectory attribute to false.

  • Files and directory management

    You can perform basic file and directory management tasks using the File interface:

    • Create files and directories using the createFile() and createDirectory() methods.

      The file or directory is created relative to the current directory that the operation is performed on.

      Note
      Do not use "." or ".." characters in the directory or file path components.
    • Retrieve a list of files or file URIs using the listFiles() and toURI() methods. The URI can be used to identify the file, for example, by using it as the src attribute on an HTML img element.

      You can retrieve file content as a DOMString with the readAsText() method. The encoding input parameter of the method defines the format in which the file content is returned.

    • Read or write to a file by first using the openStream() method to open the file. You can specify the file mode and encoding.

      The openStream() method returns a FileStream object (in mobile and wearable applications), which is a handle to the opened file. All actual operations, such as read, write, or close, on the file are performed through the FileStream object based on a position attribute, which represents the current position in the file.

    • Copy and move files and directories within the virtual file system with the copyTo() and moveTo() methods.

      If a file or directory of the same name already exists in the target location, the overwrite input parameter of the method defines whether the existing file is overwritten.

      Note
      The file or directory to be copied or moved must be located under the current directory.
    • Delete files and directories from the virtual file system using the deleteFile() and deleteDirectory() methods.

Go to top