FileSystemFileEntry

这是 实验性技术
检查 浏览器兼容性表格 在生产中使用这之前。

FileSystemFileEntry interface of the 文件系统 API represents a file in a file system. It offers properties describing the file's attributes, as well as the file() method, which creates a File object that can be used to read the file.

特性

Inherits the properties of its parent interface, FileSystemEntry , but has no properties unique to this interface.

方法

file()
创建新的 File object which can be used to read the file.

Obsolete methods

createWriter()
创建新的 FileWriter object which allows writing to the file represented by the file system entry.

基本概念

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() .

范例

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 to handle the error 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);
					

规范

规范 状态 Comment
文件和目录条目 API
The definition of 'FileSystemFileEntry' in that specification.
草案 提议 API 草案

浏览器兼容性

更新 GitHub 上的兼容性数据
Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
FileSystemFileEntry Chrome 8
Alternate Name
8
Alternate Name
Alternate Name Uses the non-standard name: FileEntry
Edge 79
Prefixed
79
Prefixed
Prefixed Implemented with the vendor prefix: webkit
Firefox 50 IE No Opera No Safari 11.1 WebView Android ≤37
Alternate Name
≤37
Alternate Name
Alternate Name Uses the non-standard name: FileEntry
Chrome Android 18
Alternate Name
18
Alternate Name
Alternate Name Uses the non-standard name: FileEntry
Firefox Android 50 Opera Android No Safari iOS 11.3 Samsung Internet Android Yes
Prefixed
Yes
Prefixed
Prefixed Implemented with the vendor prefix: webkit
createWriter
弃用 非标
Chrome 8 Edge 79 Firefox 50 — 52
不支持 50 — 52
While the createWriter() method existed, it immediately called errorCallback with the NS_ERROR_DOM_SECURITY_ERR error.
IE No Opera No Safari No WebView Android ≤37 Chrome Android 18 Firefox Android 50 — 52
不支持 50 — 52
While the createWriter() method existed, it immediately called errorCallback with the NS_ERROR_DOM_SECURITY_ERR error.
Opera Android No Safari iOS No Samsung Internet Android Yes
file Chrome 8 Edge 79 Firefox 50 IE No Opera No Safari 11.1 WebView Android ≤37 Chrome Android 18 Firefox Android 50 Opera Android No Safari iOS 11.3 Samsung Internet Android Yes

图例

完整支持
完整支持
不支持
不支持
非标。预期跨浏览器支持较差。
非标。预期跨浏览器支持较差。
弃用。不要用于新网站。
弃用。不要用于新网站。
见实现注意事项。
使用非标名称。
要求使用供应商前缀或不同名称。
要求使用供应商前缀或不同名称。

另请参阅