利用Stream模式进行文件拷贝
const fs = require('fs'); const file = fs.createReadStream("readfile.js"); const outputFile = fs.createWriteStream("outputfile.js"); file.on("data", function(data) { outputFile.write(data); }); outputFile.on("open", function(fd) { console.log("需要被写入的文件已被打开。"); }); file.on("end", function() { outputFile.end("The end.", function() { console.log("文件全部写入完毕。"); console.log("共写入%d字节数据。", outputFile.bytesWritten); }); });