let http = require('http'); http.createServer((req,res)=>{ res.end(); }).listen(3000,()=>{ console.log('start'); }) let fs = require('fs'); let readStream = fs.createReadStream('./nodedemo/1.txt'); let writeStream =fs.createWriteStream('./nodedemo/2.txt','utf-8'); readStream.pipe(writeStream);//读写流操作 // let str = ''; readStream.on('data',(chunk)=>{ str+=chunk;//chunk是 片段 //data是数据 不能修改。 }); readStream.on('end',(chunk)=>{ console.log(str);//监听读写是否结束。 })
所有操作必须在node服务器环境下去运行。