var fs = require('fs')
fs.open('../src/urls.js', 'w+', function(err, fd) {
fs.write(fd, 'const DEV = false\r\n', 0, function(err, bytes) {
})
})这段代码在执行时为什么会提示TypeError:First argument must be file descriptor,明明fd就是open传过来的descriptor啊?求解
1 回答

LEATH
TA贡献1936条经验 获得超6个赞
判断一下是不是打开失败了,如果打开失败,fd肯定就不是文件描述符了
var fs = require('fs') fs.open('../src/urls.js', 'w+', function(err, fd) { if(err!==null){ console.error(err); return; } fs.write(fd, 'const DEV = false\r\n', 0, function(err, bytes) { if(err!==null){ console.error(err); return; } }); })
添加回答
举报
0/150
提交
取消