节点readFile路径必须是字符串



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)

给定一个("Integer"(文件描述符,我如何从中读取?

> 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。

相关内容

  • 没有找到相关文章

最新更新