这是
实验性技术
检查
浏览器兼容性表格
要小心谨慎在生产中使用这之前。
FileSystemFileEntry
接口在
文件系统 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.
继承其父级接口特性,
FileSystemEntry
, but has no properties unique to this interface.
createWriter()
FileWriter
object which allows writing to the file represented by the file system entry.
要将内容写入文件,创建
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);
| 规范 | 状态 | 注释 |
|---|---|---|
|
文件和目录条目 API
在该规范中的 FileSystemFileEntry 定义。 |
草案 | 提议 API 草案 |
| 桌面 | 移动 | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
FileSystemFileEntry
|
Chrome
8
Alternate Name
|
Edge
79
Prefixed
|
Firefox 50 | IE No | Opera No | Safari 11.1 |
WebView Android
≤37
Alternate Name
|
Chrome Android
18
Alternate Name
|
Firefox Android 50 | Opera Android No | Safari iOS 11.3 |
Samsung Internet Android
Yes
Prefixed
|
createWriter
弃用
非标
|
Chrome 8 | Edge 79 |
Firefox
50 — 52
|
IE No | Opera No | Safari No | WebView Android ≤37 | Chrome Android 18 |
Firefox Android
50 — 52
|
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 |
完整支持
不支持
非标。预期跨浏览器支持较差。
弃用。不要用于新网站。
见实现注意事项。
使用非标名称。
要求使用供应商前缀或不同名称。
FileSystemFileEntry
FileError
FileException
FileHandle
FileRequest
FileSystem
FileSystemDirectoryEntry
FileSystemDirectoryEntrySync
FileSystemDirectoryReader
FileSystemDirectoryReaderSync
FileSystemEntry
FileSystemEntrySync
FileSystemFileEntrySync
FileSystemFlags
FileSystemSync
HTMLInputElement
LocalFileSystem
LocalFileSystemSync
LockedFile
元数据
Window.requestFileSystem()
Window.resolveLocalFileSystemURL()
WorkerGlobalScope.requestFileSystemSync()