Deno.readfilesync
readFileSync
-
readFileSync(path: string): Uint8Array
-
同步地读取并将文件的全部内容解析为字节数组。
TextDecoder
可以在需要的情况下可以将字节转换成字符串。 读取目录返回一个空的数据数组。Synchronously reads and returns the entire contents of a file as an array of bytes.
TextDecoder
can be used to transform the bytes to string if required. Reading a directory returns an empty data array.const decoder = new TextDecoder("utf-8"); const data = Deno.readFileSync("hello.txt"); console.log(decoder.decode(data));
需要
allow-read
权限。Requires
allow-read
permission.
参数
- ##### path: string