> ## 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` 实例。使用 `.exists()` 方法检查给定路径的文件是否存在。

```ts index.ts icon="https://mintcdn.com/span-inc/82N53aP7NFbaCVSl/icons/typescript.svg?fit=max&auto=format&n=82N53aP7NFbaCVSl&q=85&s=787d39d6a7d96d7f9540dc74344eba23" theme={null}
const path = "/path/to/package.json";
const file = Bun.file(path);

await file.exists(); // boolean;
```

***

参见 [文件 I/O](/runtime/file-io) 了解如何使用 `BunFile`。
