Node.js fs filehandle.readFile
Node.js fs filehandle.readFile(options)
- options < Object> | < string>
- encoding < string> | < null> Default: null
- flag < string> See support of file system flags. Default: ‘r’.
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.
The FileHandle has to support reading.
If one or more filehandle.read() calls are made on a file handle and then a filehandle.readFile() call is made, the data will be read from the current position till the end of the file. It doesn’t always read from the beginning of the file.
更多内容请参考：Node.js fs 文件系统，或者通过 点击对应菜单 进行查看；