FileSystemFileEntry - Web APIs 编辑
Experimental
This is an experimental technology
Check the Browser compatibility table carefully before using this in production.
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 the file()
method, which creates a File
object that can be used to read the file.
Properties
Inherits the properties of its parent interface, FileSystemEntry
, but has no properties unique to this interface.
Methods
Obsolete methods
createWriter()
- Creates a new
FileWriter
object which allows writing to the file represented by the file system entry.
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 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);
Specifications
Specification | Status | Comment |
---|---|---|
File and Directory Entries API The definition of 'FileSystemFileEntry' in that specification. | Draft | Draft of proposed API |
Browser compatibility
BCD tables only load in the browser
See also
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论