FileEntry

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 FileEntry interface of the File System API represents a file in a file system. It lets you write content to a file.

About this document

This document was last updated on March 2, 2012 and follows the W3C Specifications (Working Draft) drafted on April 19, 2011.

This specification is more or less abandoned as it didn't get significant traction among browser makers.

Basic concepts

To write content to file, create a FileWriter object by calling createWriter().

Example

The following code creates an empty file called "log.txt" (if it doesn't exist) and fills it with the text 'Meow'. Inside the success callback, event handlers are set up for error and writeend events. The text data is written to the file by creating a blob, appending text to it, and passing the blob to FileWriter.write().

function onInitFs(fs) {

  fs.root.getFile('log.txt', {create: true}, function(fileEntry) {

    // Create a FileWriter object for our FileEntry (log.txt).
    fileEntry.createWriter(function(fileWriter) {

      fileWriter.onwriteend = function(e) {
        console.log('Write completed.');
      };

      fileWriter.onerror = function(e) {
        console.log('Write failed: ' + e.toString());
      };

      // Create a new Blob and write it to log.txt.
      var bb = new BlobBuilder(); 
     // Note: window.WebKitBlobBuilder.
      bb.append('Meow');
      
      fileWriter.write(bb.getBlob('text/plain'));

    }, errorHandler);

  }, errorHandler);

}

window.requestFileSystem(window.TEMPORARY, 1024*1024, onInitFs, errorHandler);

Properties

FileEntry.fullPath
Full path to the FileEntry (string)
FileEntry.isDirectory
If the FileEntry is a directory (Boolean)
FileEntry.isFile
If the FileEntry is a file (Boolean)
FileEntry.name
Name of the FileEntry (String)

Method overview

void createWriter (FileWriterCallback successCallback, optional ErrorCallback errorCallback);
void file (FileCallback successCallback, optional ErrorCallback errorCallback);

Methods

createWriter()

Creates a new FileWriter object associated with the selected file.

void createWriter (
 in FileWriterCallback successCallback, optional ErrorCallback errorCallback
);
Parameters
successCallback
A callback that is called with the new FileWriter object.
errorCallback
A callback that is called when errors happen.
Returns
void

file()

Returns a File object associated with the selected file. You can use this to read the file's content.

void file (
  FileCallback successCallback, optional ErrorCallback errorCallback
);
Parameters
successCallback
A callback that is called with the new File.
errorCallback
A callback that is called when errors happen.
Returns
void

Browser compatibility

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support 13webkit Not supported Not supported Not supported Not supported
Feature Android Chrome for Android Firefox Mobile (Gecko) IE Phone Opera Mobile Safari Mobile
Basic support Not supported 0.16webkit Not supported Not supported Not supported Not supported

See also

Specification: File API: Directories and System SpecificationWD

Reference: File System API

Introduction: Basic Concepts About the File System API

Document Tags and Contributors

 Contributors to this page: jscissr, robinwassen, fscholz, imran1008, Cobra, teoli, Sheppy, grendel
 Last updated by: jscissr,