Stream模块有一个pipe方法,可以将两个流串起来,实现所有的数据自动从Readable流进入Writable流
"use strict"; const fs = require("fs"); //创建阅读流 const re = fs.createReadStream("test.txt", "utf-8"); //创建写入流 const wr = fs.createWriteStream("copy.txt", "utf-8"); //使用pipe方法实现将 test.txt 的内容拷贝到 copy.txt re.pipe(wr);