我想将image.png
表单/folder1
复制到/folder2
,该怎么做?
/folder1
image.png
/folder2
谢谢!
答案 0 :(得分:14)
尝试这样的事情:
var fs = require('fs');
var inStr = fs.createReadStream('/your/path/to/file');
var outStr = fs.createWriteStream('/your/path/to/destination');
inStr.pipe(outStr);
代码未经过测试,只是从内存中写下来。
答案 1 :(得分:10)
或者如果您更喜欢回调:
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!');
});
});