input/output buffers how do they relate to file open & close methods with files?
The information I have found, not sure how it helps me answer my questions above, :
buffer- is a temporary storage for data, until it is transferred from one place to another
buffer flush=( outs.flush() ) - forces buffer to be written to file
( outs.close() )- write to a physical location before I close, and unlocks the file
Input/output buffer(located in RAM)- putting/pulling data from program
open- a path to file location, locks the file, checks if file exists
output-looks to see if file exists, if not creates one and closes
buffer- is a temporary storage for data, until it is transferred from one place to another
Correct.
buffer flush=( outs.flush() ) - forces buffer to be written to file
Correct.
( outs.close() )- write to a physical location before I close, and unlocks the file
Flushes the buffer, writing any unwritten data to the file, then closes the file.
Locking and unlocking a file is an operating specific feature that may or may not be applicable.
Input/output buffer
See item one above.
open- a path to file location, locks the file, checks if file exists
What happens when you try to open a file depends on the open mode flags you pass when trying to construct or open the file. Again locking is a Operating System specific feature.
output-looks to see if file exists, if not creates one and closes
What?
Remember that "buffers" are available for many operations, not just file operations. When talking about buffers, their primary use is to speed up program execution when dealing with slow operations like writing to disk, which can me many magnitudes slower than writing to memory.
so how do input/output buffers how do they relate to file open & close methods with files?
When you open a file, the runtime will try and read from the file to fill the buffer so that data is available when you try to read. This can be implementation dependent. The first read from the file may be deferred until you actually try to read from the file.
And when you close the file, the runtime will write (flush) any remaining characters in the buffer to the output device (disk file, terminal, etc).