我有这段代码
var fd = fs.openSync(filePath,"r");
var fr = fs.readSync(fd, buffer, 0, size, 0);
它会像那样抛出错误
events.js:72
throw er; // Unhandled 'error' event
^
Error: OK, open 'C:\Users\iahmed16\Desktop\eclipse WS\test\images\af31a9e0a98939be82f887b0005c21752e71425e.jpg'
答案 0 :(得分:8)
错误似乎意味着你有too many file descriptions open。
您必须确保在某些时候close()
他们。
var fd = fs.openSync(filePath,"r");
var fr = fs.readSync(fd, buffer, 0, size, 0);
fs.closeSync(fd);
至于如何处理错误,您可以try...catch
使用throw
n个错误:
try {
var fd = fs.openSync(filePath,"r");
var fr = fs.readSync(fd, buffer, 0, size, 0);
fs.closeSync(fd);
} catch (e) {
console.log('Error:', e);
}