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

过时
This feature is obsolete. Although it may still work in some browsers, its use is discouraged since it could be removed at any time. Try to avoid using it.

非标
此特征是非标准的,且不在标准轨道中。不要在面向 Web 的生产站点中使用它:它不适用于每个用户。实现之间可能存在大的不兼容性,且行为将来可能改变。

FileSystemFileEntry 接口方法 createWriter() 返回 FileWriter object which can be used to write data into the file represented by the directory entry.

句法

FileSystemFileEntry.createWriter(successCallback[, errorCallback]);
					

参数

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 可选
If provided, this must be a method which is caled when an error occurs while trying to create the FileWriter . This callback receives as input a FileError object describing the error.

返回值

undefined .

范例

此例子建立方法, writeToFileEntry() ,将文本字符串输出到传入目录条目对应文件。

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.

此 API 没有正式的 W3C 或 WHATWG (Web 超文本应用程序技术工作组) 规范。

浏览器兼容性

The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request. 更新 GitHub 上的兼容性数据
桌面 移动
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet
createWriter 弃用 非标 Chrome 8 Edge 79 Firefox 50 — 52
不支持 50 — 52
While the createWriter() method existed, it immediately called errorCallback 采用 NS_ERROR_DOM_SECURITY_ERR 错误。
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 采用 NS_ERROR_DOM_SECURITY_ERR 错误。
Opera Android No Safari iOS No Samsung Internet Android Yes

图例

完整支持

完整支持

不支持

不支持

非标。预期跨浏览器支持较差。

非标。预期跨浏览器支持较差。

弃用。不要用于新网站。

弃用。不要用于新网站。

见实现注意事项。

另请参阅

元数据

  • 最后修改: