tencent cloud

Last updated: 2025-03-11 19:41:08
open
Last updated: 2025-03-11 19:41:08
The open built-in function is used to open files.
open(filePath: string, mode?: '' | 'b'): string | ArrayBuffer

Parameters

Parameter
Type
Description
filePath
string
The relative path to the file.
mode?
'' or 'b'.
Open mode (optional). For text files, it is not necessary to specify a mode, and the return value is a string; for binary files, 'b' mode should be passed, and the return value is an ArrayBuffer.

Return

Type
Description
string or ArrayBuffer.
File data.

Samples

Open files:
export default function () {
let data = open('test1.json'); // Open text files by default.
console.log(data); // {"a":"b"}
data = open('test2.bin', 'b'); // Open binary files in 'b' mode.
console.log(data); // [object ArrayBuffer]
};

Was this page helpful?
You can also Contact Sales or Submit a Ticket for help.
Yes
No

Feedback