> ## Documentation Index
> Fetch the complete documentation index at: https://mintlify.com/zhcndoc/bun/llms.txt
> Use this file to discover all available pages before exploring further.

# Read a file as a string

> Read text files with Bun

Bun provides fast file reading with `Bun.file()`.

## Read File to String

```typescript theme={null}
const file = Bun.file("data.txt");
const text = await file.text();
console.log(text);
```

## Synchronous Read

```typescript theme={null}
import { readFileSync } from "node:fs";

const text = readFileSync("data.txt", "utf-8");
console.log(text);
```

## Error Handling

```typescript theme={null}
try {
  const file = Bun.file("data.txt");
  const text = await file.text();
  console.log(text);
} catch (error) {
  console.error("Failed to read file:", error);
}
```

See [File I/O](/api/file-io) for complete documentation.
