> ## Documentation Index
> Fetch the complete documentation index at: https://bun.ll1025.cn/llms.txt
> Use this file to discover all available pages before exploring further.

# 读取文件为 Uint8Array

`Bun.file()` 函数接受一个路径并返回 `BunFile` 实例。`BunFile` 继承自 `Blob`，因此你可以以多种格式惰性读取文件。

要将文件读取为 `Uint8Array`，请使用 `.bytes()`。

```ts theme={null}
const path = "/path/to/package.json";
const file = Bun.file(path);

const byteArray = await file.bytes();

byteArray[0]; // 第一个字节
byteArray.length; // 字节数组长度
```

***

参见 [类型数组](/runtime/binary-data#typedarray) 了解如何在 Bun 中使用 `Uint8Array` 和其他二进制数据格式。
