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

# 读取文件到 Uint8Array

`Bun.file()` 函数接受一个路径并返回一个 `BunFile` 实例。`BunFile` 类继承自 `Blob`，允许你以多种格式懒加载地读取文件。

要将文件读取到 `Uint8Array` 实例中，可以使用 `.bytes()` 方法获取 `BunFile` 的内容。

```ts theme={"theme":{"light":"github-light","dark":"dracula"}}
const path = "/path/to/package.json";
const file = Bun.file(path);

const byteArray = await file.bytes();

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

***

有关在 Bun 中使用 `Uint8Array` 和其他二进制数据格式的更多信息，请参阅 [API > 二进制数据 > 类型化数组](/runtime/binary-data#typedarray)。
