运行时包管理器打包器测试运行器代码检查格式化指南参考博客反馈

检查文件是否存在

Bun.file() 函数接受一个路径并返回一个 BunFile 实例。使用 .exists() 方法可以检查给定路径下的文件是否存在。

index.ts
const path = "/path/to/package.json";
const file = Bun.file(path);

await file.exists(); // 布尔值;

请参阅文件 I/O,了解有关使用 BunFile 的更多信息。