gpt4 book ai didi

ruby - `File` 对象的访问模式之间的差异(即 w+、r+)

转载 作者:数据小太阳 更新时间:2023-10-29 06:20:33 24 4
gpt4 key购买 nike

在Ruby中使用文件时,r+w+模式有什么区别? a+ 模式怎么样?

最佳答案

参见 http://www.tutorialspoint.com/ruby/ruby_input_output.htm

引用:

r
Read-only mode. The file pointer is placed at the beginning of the file. This is the default mode.

r+
Read-write mode. The file pointer will be at the beginning of the file.

w
Write-only mode. Overwrites the file if the file exists. If the file does not exist, creates a new file for writing.

w+
Read-write mode. Overwrites the existing file if the file exists. If the file does not exist, creates a new file for reading and writing.

a
Write-only mode. The file pointer is at the end of the file if the file exists. That is, the file is in the append mode. If the file does not exist, it creates a new file for writing.

a+
Read and write mode. The file pointer is at the end of the file if the file exists. The file opens in the append mode. If the file does not exist, it creates a new file for reading and writing.

(强调我的。)

r+、w+ 和 a+ 都可以读写。 w+ 截断文件。 a+ 追加。如果文件不存在,w+ 和 a+ 都会创建文件。)

关于ruby - `File` 对象的访问模式之间的差异(即 w+、r+),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1581674/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com