Mode | Meaning
-----+--------------------------------------------------------
"r" | Read-only, starts at beginning of file (default mode).
-----+--------------------------------------------------------
"r+" | Read-write, starts at beginning of file.
-----+--------------------------------------------------------
"w" | Write-only, truncates existing file
| to zero length or creates a new file for writing.
-----+--------------------------------------------------------
"w+" | Read-write, truncates existing file to zero length
| or creates a new file for reading and writing.
-----+--------------------------------------------------------
"a" | Write-only, starts at end of file if file exists,
| otherwise creates a new file for writing.
-----+--------------------------------------------------------
"a+" | Read-write, starts at end of file if file exists,
| otherwise creates a new file for reading and
| writing.
-----+--------------------------------------------------------
"b" | (DOS/Windows only) Binary file mode (may appear with
| any of the key letters listed above)
File open mode in Ruby
文件操作模式详解
最新推荐文章于 2025-01-25 11:03:16 发布
本文详细介绍了文件操作的各种模式,包括只读、读写、写入等,并解释了每种模式的特点及应用场景。例如'r'模式表示只读且从文件开头开始读取;'w+'模式表示读写并会截断现有文件至零长度或创建新文件用于读写。
1510

被折叠的 条评论
为什么被折叠?



