fsPromises.writeFile(file, data[, options])
file
<string> | <Buffer> | <URL> | <FileHandle> 文件名或FileHandle
data
<string> | <Buffer> | <Uint8Array>options
<Object> | <string>encoding
<string> | <null> 默认值:'utf8'
mode
<integer> 默认值:0o666
flag
<string> 请参阅对文件系统flags
的支持。 默认值:'w'
。
- 返回: <Promise>
异步地将数据写入文件,如果文件已经存在,则替换该文件。
data
可以是字符串或缓冲区。
如果 data
是缓冲区,则忽略 encoding
选项。
如果 options
是字符串,则它指定编码。
任何指定的 FileHandle
都必须支持写入。
file
<string> | <Buffer> | <URL> | <FileHandle> filename orFileHandle
data
<string> | <Buffer> | <Uint8Array>options
<Object> | <string>encoding
<string> | <null> Default:'utf8'
mode
<integer> Default:0o666
flag
<string> See support of file systemflags
. Default:'w'
.
- Returns: <Promise>
Asynchronously writes data to a file, replacing the file if it already exists.
data
can be a string or a buffer. The Promise
will be resolved with no
arguments upon success.
The encoding
option is ignored if data
is a buffer.
If options
is a string, then it specifies the encoding.
Any specified FileHandle
has to support writing.
It is unsafe to use fsPromises.writeFile()
multiple times on the same file
without waiting for the Promise
to be resolved (or rejected).