fs.createWriteStream
时间: 2024-01-21 10:02:11 浏览: 68
node.js中的fs.createWriteStream方法使用说明
fs.createWriteStream is a method in Node.js that creates a writable stream to a specified file path. It returns a WriteStream object that can be used to write data to the file. The method takes two arguments: the file path and an optional options object. The options object can be used to specify the encoding, mode, and flag used when writing to the file.
Example usage:
```javascript
const fs = require('fs');
const writeStream = fs.createWriteStream('output.txt');
writeStream.write('Hello, world!');
writeStream.end();
```
This code creates a writable stream to a file named 'output.txt' and writes the string 'Hello, world!' to it. The writeStream.end() method is called to indicate that no more data will be written to the stream, which closes the stream and the file.
阅读全文