FileSystemFileEntry.createWriter()

Deprecated: This feature is no longer recommended. Though some browsers might still support it, it may have already been removed from the relevant web standards, may be in the process of being dropped, or may only be kept for compatibility purposes. Avoid using it, and update existing code if possible; see the compatibility table at the bottom of this page to guide your decision. Be aware that this feature may cease to work at any time.

Non-standard: This feature is non-standard and is not on a standards track. Do not use it on production sites facing the Web: it will not work for every user. There may also be large incompatibilities between implementations and the behavior may change in the future.

The FileSystemFileEntry interface's method createWriter() returns a FileWriter object which can be used to write data into the file represented by the directory entry.

Syntax

createWriter(successCallback)
createWriter(successCallback, errorCallback)

Parameters

successCallback

A callback function which is called when the FileWriter has been created successfully; the FileWriter is passed into the callback as the only parameter.

errorCallback Optional

If provided, this must be a method which is called when an error occurs while trying to create the FileWriter. This callback receives as input a FileError object describing the error.

Return value

None (undefined).

Examples

This example establishes a method, writeToFileEntry(), which outputs a text string to the file corresponding to the passed-in directory entry.

function writeToFileEntry(entry, text) {
  entry.createWriter(function(fileWriter) {
    let data = Blob([text], { type: "text/plain" });

    fileWriter.write(data);
  }, function(fileError) {
    /* do whatever to handle the error */
  });
}

The success callback for the createWriter() call takes the text which was passed in and creates a new Blob object of type text/plain that contains the passed text. This blob is then output to the FileWriter object to be written to the file.

Specifications

This feature is not part of any specification anymore. It is no longer on track to become a standard.

Browser compatibility

BCD tables only load in the browser

See also