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

# 将 Response 写入文件

此代码片段将一个 `Response` 写入指定路径的磁盘。Bun 会根据响应的 `Content-Type` 头来消费 `Response` 的主体内容。

它使用快速的 [`Bun.write()`](/runtime/file-io#writing-files-bun-write) API 高效地将数据写入磁盘。第一个参数是一个 *目标*，比如绝对路径或 `BunFile` 实例。第二个参数是要写入的 *数据*。

```ts theme={"theme":{"light":"github-light","dark":"dracula"}}
const result = await fetch("https://bun.com");
const path = "./file.txt";
await Bun.write(path, result);
```

***

完整的 `Bun.write()` 文档请查看[文档 > API > 文件 I/O](/runtime/file-io#writing-files-bun-write)。
