1、
// fs.writeFileSync(pathNewFile, fs.readFileSync(fileName));
2、
fs.createReadStream(fileName).pipe(fs.createWriteStream(pathNewFile));
3、
1 fs.readdir(imDataDir, function(err, files){ 2 if(err){ 3 return false; 4 } 5 files.forEach(function(fileName){ 6 var director = path.join(fileDir, fileName); 7 fs.stat(director, function(err, stats){ 8 if(err){ 9 return false; 10 } 11 if(stats.isFile()){ 12 if(fs.existsSync(director)){ 13 try { 14 let newPathFile = path.join(keyDir,fileName); 15 var readStream = fs.createReadStream(director) 16 var writeStream = fs.createWriteStream(newPathFile); 17 readStream.pipe(writeStream); 18 fs.unlinkSync(director); 19 }catch (e) { 20 console.log(e); 21 } 22 } 23 } 24 }); 25 }); 26 });