r +和w +模式之间的确切区别是什么? [英] What is the exact difference between r+ and w+ modes?
问题描述
我试图使用它们两个打开文件,但结果相同.
I tried to use both of them opening a file but got the same result.
w +
不存在,而 r +
不存在,则应该创建一个新文件.这是唯一的区别吗?
w+
is supposed to create a new file if it doesn't exist while r+
not.
Is this the only difference?
例如,这是一个初始文件 file.txt
For example, this is an initial file file.txt
Line 1
Line 2
Line 3
1)实施 r +
模式(写出"hello"一词)后, file.txt
/p>
1) file.txt
after implementing of r+
mode (writing the word "hello")
hello
2)实施 w +
模式后, file.txt
>
2) file.txt
after implementing of w+
mode
hello
我猜想 r +
会将输入追加到文件的开头.
I guessed that r+
would append an input to the beginning of the file.
因此,第一个区别是关于创建一个不存在的文件,第二个区别是r +在w +被截断的同时会被覆盖,对吗?(而不是出现了一个问题,即覆盖和截断是否是相同的概念)
EDITED: So, the 1st difference is about creating a file that doesn't exist and the 2nd difference is that r+ overwrites while w+ truncates, right? (than the question arises whether overwriting and truncating are the same concepts or not)
推荐答案
先删除 file.txt
,您将了解其中的区别.
Remove file.txt
first and you'll understand the difference.
w +
将创建文件.
这篇关于r +和w +模式之间的确切区别是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!