1

I understand that most languages have the ability to open files for reading, writing or both. What is the point of opening a file for just one or the other? Is it faster to open a file for reading only or writing only than opening it for both? Or is there other reasons?

Tacodiva
  • 391
  • 2
  • 17
  • Does this answer your question? https://stackoverflow.com/questions/1466000/difference-between-modes-a-a-w-w-and-r-in-built-in-open-function – j3st Jun 13 '21 at 05:56
  • @j3st No. The other options make scene to have (where the initial position is, truncate, etc.) but my questions is asking why is 'read' 'write' or 'read and write' even an option. Why would you choose one over the other when you can just always open for reading and writing. – Tacodiva Jun 13 '21 at 06:05
  • 2
    At least many optimizations can be done if the system knows you’ll never read, or never write the file. For example, reading can use one buffer for anyone reading at that point and not care about changes since nobody is changing anything. Writing could write directly and not care about if you also want to read. Not to mention some “files” are read only or write only, so it’s nice to get an error immediately if you want to, say, read from a sound output device, or write to a microphone. – Sami Kuhmonen Jun 13 '21 at 06:13

0 Answers0