节点readFile路径必须是字符串

时间:2016-10-25 18:56:57

标签: javascript node.js file-descriptor

fs.readFileSync的文档是

file <String> | <Buffer> | <Integer> filename or file descriptor

但是

require('fs').readFile(0);

导致错误

TypeError: path must be a string
at TypeError (native)
at Object.fs.readFile (fs.js:250:11)
at repl:1:15
at REPLServer.defaultEval (repl.js:252:27)
at bound (domain.js:287:14)
at REPLServer.runBound [as eval] (domain.js:300:12)
at REPLServer.<anonymous> (repl.js:417:12)
at emitOne (events.js:82:20)
at REPLServer.emit (events.js:169:7)
at REPLServer.Interface._onLine (readline.js:211:10)

给定(&#34; Integer&#34;)文件描述符,我该如何阅读?

1 个答案:

答案 0 :(得分:0)

> require('fs').readFileSync(0);
Error: EBADF: bad file descriptor, fstat
at Error (native)
at Object.fs.fstatSync (fs.js:977:18)
at tryStatSync (fs.js:462:13)
at Object.fs.readFileSync (fs.js:510:12)
at repl:1:15
at sigintHandlersWrap (vm.js:22:35)
at sigintHandlersWrap (vm.js:96:12)
at ContextifyScript.Script.runInThisContext (vm.js:21:12)
at REPLServer.defaultEval (repl.js:313:29)
at bound (domain.js:280:14)

节点版本6.7.0。