Skip to content

FileSystemManager.readFileSync ​

JS
    FileSystemManager.readFileSync(
        string filePath,
        string encoding,
        string position,
        string length)

Reads a file

The synchronous version of FileSystemManager.readFile

Parameters

PropertyValue TypeDescription
filePathstringPath of the file to read
encodingstringSpecifies the character encoding for reading the file. See the figure below for valid values.
positionnumberStart reading from the specified position in the file. If not specified, reading starts from the beginning of the file. The read range is the left-closed, right-open interval [position, position+length). Valid range: [0, fileLength - 1]. Unit: byte
lengthnumberSpecifies the length of the file to read. If not specified, reading continues to the end of the file. Valid range: [1, fileLength]. Unit: byte

Valid values of encoding:

ValueDescription
utf8utf-8 encoding
utf-8utf-8 encoding
binaryBinary

Return Value

  • string|ArrayBuffer data: File content

Parameters for caught exceptions

  • string error: Returns error information. See the figure below for valid values.

Valid values of error:

Error InformationDescription
no such file or directoryThe directory of the specified filePath does not exist