> ## 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.

# 读取文件为字符串

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

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

const text = await file.text();
// string
```

***

Bun 从当前工作目录解析相对路径。

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