fsPromises.readFile(path[, options])
path<string> | <Buffer> | <URL> | <FileHandle> 文件名或FileHandleoptions<Object> | <string>encoding<string> | <null> 默认值:nullflag<string> 请参阅对文件系统flags的支持。 默认值:'r'。
- 返回: <Promise>
异步地读取文件的全部内容。
如果未指定编码(使用 options.encoding),则数据作为 Buffer 对象返回。
否则,数据将为字符串。
如果 options 是字符串,则它指定编码。
当 path 是目录时,fsPromises.readFile() 的行为是特定于平台的。
在 macOS、Linux 和 Windows 上,promise 将使用错误拒绝。
在 FreeBSD 上,将返回目录内容的表示。
任何指定的 FileHandle 必须支持读取。
path<string> | <Buffer> | <URL> | <FileHandle> filename orFileHandleoptions<Object> | <string>encoding<string> | <null> Default:nullflag<string> See support of file systemflags. Default:'r'.
- Returns: <Promise>
Asynchronously reads the entire contents of a file.
The Promise is resolved with the contents of the file. If no encoding is
specified (using options.encoding), the data is returned as a Buffer
object. Otherwise, the data will be a string.
If options is a string, then it specifies the encoding.
When the path is a directory, the behavior of fsPromises.readFile() is
platform-specific. On macOS, Linux, and Windows, the promise will be rejected
with an error. On FreeBSD, a representation of the directory's contents will be
returned.
Any specified FileHandle has to support reading.