filehandle.write(string[, position[, encoding]])


string 写入文件。

position 指从文件开头数据应被写入的偏移量。

参见 pwrite(2)

encoding 是预期的字符串编码。

对于这种情况,请使用 fs.createWriteStream()

在 Linux 上,以追加模式打开文件时,位置写入不起作用。 内核会忽略位置参数,并始终将数据追加到文件末尾。

Write string to the file. If string is not a string, then the value will be coerced to one.

The Promise is resolved with an object containing a bytesWritten property identifying the number of bytes written, and a buffer property containing a reference to the string written.

position refers to the offset from the beginning of the file where this data should be written. If the type of position is not a number the data will be written at the current position. See pwrite(2).

encoding is the expected string encoding.

It is unsafe to use filehandle.write() multiple times on the same file without waiting for the Promise to be resolved (or rejected). For this scenario, use fs.createWriteStream().

On Linux, positional writes do not work when the file is opened in append mode. The kernel ignores the position argument and always appends the data to the end of the file.