3 回答
TA贡献1799条经验 获得超9个赞
fs.write(fd, buffer, offset, length, position, callback)您需要等待回调,以确保缓冲区被写入磁盘。没有缓冲。 fs.writeFile(filename, data, [encoding], callback)所有数据必须同时存储;不能执行顺序写入。 fs.createWriteStream(path, [options])创建 WriteStream,这很方便,因为您不需要等待回调。但同样,它没有缓冲。
A WriteStreamnn+1
换言之:
WriteStreamStream
write("a")write("b")write("c")fs.write(new Buffer("a"))fs.write(new Buffer("b"))fs.write(new Buffer("c"))fs.write(new Buffer ("abc"))
cork()uncork()
BufferedOutputStream, BufferedWriter
TA贡献1827条经验 获得超8个赞
var fs = require('fs');var stream = fs.createWriteStream("my_file.txt");stream.once('open', function(fd) {
stream.write("My first row\n");
stream.write("My second row\n");
stream.end();});添加回答
举报
