# 文件已关闭

- **ID:** `go/os-file-already-closed`
- **领域:** go
- **类别:** io_error
- **验证级别:** ai_generated
- **修复率:** 80%

## 根因

尝试对已关闭的文件进行读、写或关闭操作，通常是由于双重关闭或在 defer Close() 后使用文件。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| 1.13 | active | — | — |
| 1.14 | active | — | — |
| 1.15 | active | — | — |

## 解决方案

1. **** (95% 成功率)
   ```
   Use a sync.Once to ensure Close() is called only once.
   ```
2. **** (90% 成功率)
   ```
   Set the file variable to nil after Close() and check for nil before using.
   ```

## 无效尝试

- **** — The file pointer is not nil after closing; it's the underlying descriptor that is invalid. (70% 失败率)
- **** — Sync() does not prevent the file from being closed. (60% 失败率)
