添加链接
link管理
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
  • 返回: <string> | <Buffer>
  • 返回 path 的内容。

    有关详细信息,请参阅此 API 的异步版本的文档: fs.readFile()

    如果指定了 encoding 选项,则此函数返回字符串。 否则它返回缓冲区。

    fs.readFile() 类似,当路径为目录时, fs.readFileSync() 的行为是特定于平台的。

    import { readFileSync } from 'node:fs';
    // macOS、Linux 和 Windows
    readFileSync('<directory>');
    // => [Error: EISDIR: illegal operation on a directory, read <directory>]
    //  FreeBSD
    readFileSync('<directory>'); // => <data>
    History VersionChanges v7.6.0

    The path parameter can be a WHATWG URL object using file: protocol.

    v5.0.0

    The path parameter can be a file descriptor now.

    v0.1.8

    Added in: v0.1.8

  • path <string> | <Buffer> | <URL> | <integer> filename or file descriptor
  • options <Object> | <string>
  • encoding <string> | <null> Default: null
  • flag <string> See support of file system flags . Default: 'r' .
  • Returns: <string> | <Buffer>
  • Returns the contents of the path .

    For detailed information, see the documentation of the asynchronous version of this API: fs.readFile() .

    If the encoding option is specified then this function returns a string. Otherwise it returns a buffer.

    Similar to fs.readFile() , when the path is a directory, the behavior of fs.readFileSync() is platform-specific.

    import { readFileSync } from 'node:fs';
    // macOS, Linux, and Windows
    readFileSync('<directory>');
    // => [Error: EISDIR: illegal operation on a directory, read <directory>]
    //  FreeBSD
    readFileSync('<directory>'); // => <data>