> For the complete documentation index, see [llms.txt](https://zg-zhang.gitbook.io/note/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://zg-zhang.gitbook.io/note/deno/1.md).

# Deno API

## Deno.readFile

```typescript
export function readFile(path: string): Promise<Uint8Array>;
```

使用实例：

```typescript
const decoder = new TextDecoder("utf-8");
const data = await Deno.readFile("hello.txt");
console.log(decoder.decode(data));
```

## Deno.writeFile

```typescript
export function writeFile(
    path: string,
    data: Uint8Array,
    options?: WriteFileOptions
): Promise<void>
```

使用实例：

```typescript
const encoder = new TextEncoder();
const data = encoder.encode("Hello world");
// overwrite "hello1.txt" or create it
await Deno.writeFile("hello1.txt", data);
// only works if "hello2.txt" exists
await Deno.writeFile("hello2.txt", data, {create: false});
// set permissions on new file
await Deno.writeFile("hello3.txt", data, {mode: 0o777});
// add data to end of the file
await Deno.writeFile("hello4.txt", data, {append: true});
```
