//写入文件 function writeFile(){ console.log(’\nWrite file’); fs.open(‘t1.txt’,‘w+’,function(err,fd){ var data=‘Yiibai.com - Simply Easy Learning!’; buffer.write(data); fs.write(fd,buffer,0,data.length,0,function(err,bytes){ if(err)console.log(err.stack); console.log(bytes+“written!”) }) }) } writeFile() //写入流 var fs=require(‘fs’); var data=“Yi”; //创建一个可写流也会创建一个test1.txt文件 var writerStream=fs.createWriteStream(‘test1.txt’); //将数据写入流 writerStream.write(data,‘UTF8’); //标记文件的结束 writerStream.end();
↧