Concept
How are files read, written, and properly managed?
"Depending on the language, the act of opening a file may determine if it will be read from or written to. When read from, the file is referred to as an input file while a file that is written to is an output file. Languages may also have different API or functions to read/write or append to a file. A file may be read line by line until the end of the file has been reached. Languages usually support this by using a special End Of File (EOF) flag or value to indicate the end of a file has been reached. A file is a resource just like memory and we need to properly manage it. We need to make sure that we close a file once we are finished processing it. Depending on the language and other factors such as the operating system, failure to close a file may result in corrupted data. Though a file may be closed automatically for us when the program terminates, its still best practice to properly close it."
Related Ideas
- What is the difference between absolute and relative file paths?ComputerScienceOne · Paths
- How can you refer to directories and files at different levels of a directory tree?ComputerScienceOne · Error Handling
- How is the Linux file system organized?ComputerScienceOne · Error Handling
- What types of errors can occur when processing files?ComputerScienceOne · Error Handling
- When should data be stored as binary or text files?ComputerScienceOne · Buffered and Unbuffered