2011-03-06 35 views

回答

10

尝试这样:

var fs = require('fs'); 

var inStr = fs.createReadStream('/your/path/to/file'); 
var outStr = fs.createWriteStream('/your/path/to/destination'); 

inStr.pipe(outStr); 

代码没有进行测试,从内存中只是写下来。

8

或者如果你喜欢回调:

fs = require('fs') 
fs.readFile('folder1/image.png', function (err, data) { 
    if (err) throw err; 
    fs.writeFile('folder2/image.png', data, function (err) { 
     if (err) throw err; 
     console.log('It\'s saved!'); 
    }); 
}); 
+1

upvoted的实际 “处理” 错误 – 2015-01-23 09:37:18