Stream模塊有一個pipe方法,能夠將兩個流串起來,實現全部的數據自動從Readable流進入Writable流ui
"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);