Was sind die Ruby File.open-Modi und -Optionen?


Antworten:


377

In der Dokumentation zum Ruby IO-Modul , nehme ich an.

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").

2
Danke für die Liste der Moes. Aber wo ist die Liste für die Optionen: File.open (Dateiname, Modus = "r" [, opt]) => Datei
— nie_had_a_name

1
Wo hast du das gefunden? Leider kann ich File.open(filename, mode="r" [, opt])in der Dokumentation nicht finden .
— Daniel O'Hara

@floatless. in der API für File-Klasse. Gehen Sie zur Klasse "Datei" und klicken Sie auf die Methode "Öffnen".
— nie_had_a_name

1
Ich nehme an, es ist ein Experiment, das noch nicht implementiert ist. Und ich verstehe immer noch nicht, welche API Sie sprechen. Gib einen Link.
— Nakilon

1
Wenn ich eine Kleinigkeit für "a +" hinzufügen darf, beginnt das Lesen am Anfang der Datei, nicht genau am Ende der Datei (falls sich jemand wundert).
— Yoppuyoppu

Durch die Nutzung unserer Website bestätigen Sie, dass Sie unsere Cookie-Richtlinie und Datenschutzrichtlinie gelesen und verstanden haben.
Licensed under cc by-sa 3.0 with attribution required.