FileSystemFileEntry
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 of the File System API represents a file in a file system. It offers properties describing the file's attributes, as well as methods for creating a FileWriter
object to write to the file or a File
object to read the file.
Because this is a non-standard API, whose specification is not currently on a standards track, it's important to keep in mind that not all browsers implement it, and those that do may implement only small portions of it. Check the Browser compatibility section for details.
Properties
Inherits the properties of its parent interface, FileSystemEntry
, but has no properties unique to this interface.
Methods
createWriter()
- Creates a new
FileWriter
object which allows writing to the file represented by the file system entry. file()
- Creates a new
File
object which can be used to read the file.
Basic concepts
To write content to file, create a FileWriter
object by calling createWriter()
. To read a file, obtain a File
object representing its contents by calling file()
.
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 FileSystemFileEntry (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(); bb.append('Meow'); fileWriter.write(bb.getBlob('text/plain')); }, errorHandler); }, errorHandler); } window.requestFileSystem(window.TEMPORARY, 1024*1024, onInitFs, errorHandler);
Specifications
Specification | Status | Comment |
---|---|---|
File and Directory Entries API | Editor's Draft | Draft of proposed API |
This API has no official W3C or WHATWG specification.
Browser compatibility
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari (WebKit) |
---|---|---|---|---|---|
Basic support | 13 webkit | 50 (50) | No support | No support | No support |
createWriter() |
13 webkit | No support[1] | No support | No support | No support |
Feature | Android | Chrome for Android | Firefox Mobile (Gecko) | IE Phone | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|---|
Basic support | No support | 0.16webkit | 50.0 (50) | No support | No support | No support |
createWriter() |
No support | 0.16webkit | No support[1] | No support | No support | No support |
[1] While the createWriter()
method exists in Firefox 50, it is not supported, and immediately reports an NS_ERROR_DOM_SECURITY_ERR
error to the error callback.
See also
License
© 2016 Mozilla Contributors
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-us/docs/web/api/filesystemfileentry