什么是Ruby File.open模式和选项? [英] What are the Ruby File.open modes and options?

查看:654
本文介绍了什么是Ruby File.open模式和选项?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Ruby的 File.open 以模式和选项作为参数。在哪里可以找到完整的模式和选项列表?

解决方案

Ruby IO模块文档,我想是。
$ b

 模式|含义
----- + --------------------------------------- -----------------
r|只读,从文件开始(默认模式)开始。
----- + ---------------------------------------- ----------------
r +|读写,从文件开始处开始。
----- + ---------------------------------------- ----------------
w|只写,截断现有文件
|以零长度或创建一个新的文件写入。
----- + ---------------------------------------- ----------------
w +|读写,将现有文件截断为零长度
|或创建一个新的文件进行读写。
----- + ---------------------------------------- ----------------
a|只写,如果文件存在,则从文件结尾开始,
|否则创建一个新的文件进行写入。
----- + ---------------------------------------- ----------------
a +|读写,如果文件存在,则从文件末尾开始,
|否则创建一个新的文件阅读和
|写作。
----- + ---------------------------------------- ----------------
b|二进制文件模式(可能与
|上面列出的任何关键字母一起出现)。
|抑制EOL - Windows上的CRLF转换。和
|除非明确
|,否则将外部编码设置为ASCII-8BIT指定。
----- + ---------------------------------------- ----------------
t|文本文件模式(可能与
|以上列出的任何关键字母(b除外)一起出现)。


Ruby's File.open takes modes and options as arguments. Where do I find a complete list of modes and options?

解决方案

In Ruby IO module documentation, I suppose.

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"  |  Binary file mode (may appear with
     |  any of the key letters listed above).
     |  Suppresses EOL <-> CRLF conversion on Windows. And
     |  sets external encoding to ASCII-8BIT unless explicitly
     |  specified.
-----+--------------------------------------------------------
"t"  |  Text file mode (may appear with
     |  any of the key letters listed above except "b").

这篇关于什么是Ruby File.open模式和选项?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆