Deno.readfile
readFile
-
readFile(path: string): Promise<Uint8Array>
-
读取并将文件的全部内容解析为字节数组。
TextDecoder
可以在需要的情况下可以将字节转换成字符串。 读取目录返回一个空的数据数组。Reads and resolves to 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 = await Deno.readFile("hello.txt"); console.log(decoder.decode(data));
需要
allow-read
权限。Requires
allow-read
permission.
参数
- ##### path: string