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

```ts index.ts icon="https://mintcdn.com/bun-zhcndoc/cnUTwgMuf4cCrwC-/icons/typescript.svg?fit=max&auto=format&n=cnUTwgMuf4cCrwC-&q=85&s=e7767043c9e885c34f2d6c8fe2a95217" theme={"theme":{"light":"github-light","dark":"dracula"}}
const path = "/path/to/package.json";
const file = Bun.file(path);

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

***

有关使用 `BunFile` 的更多信息，请参见 [API > 文件 I/O](/runtime/file-io)。
