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

# 将文件作为字符串读取

`Bun.file()` 函数接受一个路径并返回一个 `BunFile` 实例。`BunFile` 类继承自 `Blob`，允许你以多种格式懒惰地读取文件。使用 `.text()` 以字符串形式读取文件内容。

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

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

***

任何相对路径都会相对于项目根目录（包含最近的 `package.json` 文件的目录）进行解析。

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