Chapter 10, Files
Generally speaking, what is a delimiter? How are delimiters typically used in files?
1. A delimiter is simply a predefined character or set of characters that marks the end o a each piece of data. 2. The delimiter's purpose is to separate the different items that are stored in a file.
What is a file's read position? Initially, where is the read position when an input file is opened?
1. A file's read position marks the location of the next item that will be read from the file. 2. When an input file is opened, its read position is initially set to the first item I'm the file.
What is a record? What is a field?
1. A record is a complete set of data that describes one item. 2. A field is a single piece of data within a record.
In what mode do you open a file if you want to write data to it, but you do not want to erase the file's existing contents? When you write data to such a file, to what part of the file is the data written?
1. Append mode: if the file already exists, it will not be erased. If the file does not exist, it will be created. 2. When data is written to the file, it will be written at the end of the file's current contents.
What three steps must be taken by a program when it uses a file?
1. Open the file: Create a connection between the file and the program. 2. Process the file: data is either written to the file or read from the file. 3. Close the file: disconnect the file from the program.
Describe the way that you use a temporary file in a program that modifies a record in a sequential access file.
1. Open the original file. (This will erase the contents of the original file) 2. Open the temporary file for input. 3. Read each record in the temporary file and then write it to the original file. (This copies all of the records from the temporary file to the original file.) 4. Close the original and temporary files.
What are the two types of file access? What is the difference between these two?
1. Sequential Access File: access the file from the beginning to the end of the file. 2. Direct Access File (Random Access File): you can jump directly to any piece of data without reading the data that comes before it.
In general, what are the two types of files? What is the difference between these two types of files?
1. Text file: contains data that has been encoded as text, using a scheme such as ASCII or Unicode. 2. Binary file: contains data that has not been converted to text. 3. the difference is you cannot view the contents of a binary file with a text editor.
When writing a program that performs an operation on a file, what two file-associated names do you have to work with in your code?
1. The filename that identifies the file on the computers disk. 2. The internal name that is similar to a variable name.
What is the purpose of closing a file?
Closing a file disconnects the program from the file. The process of closing an output file forces any unsaved data that remains in the buffer to be written to the file. In some systems, failure to close an output file can cause a loss of data.
Where are files normally stored?
Data is saved in a file, which is usually stored on a computer's disk.
What is the purpose of opening a file?
Once you have opened an output file you can write data to it.
What would it mean if the expression oof(myFile) were to return True?
The EOF function accepts a file's internal name as an argument, and returns True if the end of the file has been reached or False if the end of the file has not been reached.
Is it acceptable for a program to attempt to read beyond the end of a file?
The program needs some way of knowing when the end of the file has been reached so it will not try to read beyond it.
In many systems, what is written at the end of a file?
The purpose of the End of File (EOF) marker is to indicate where the file's contents end.
What is the purpose of an EOF function?
The purpose of the End of File (EOF) marker is to indicate where the file's contents end.
In most programming languages, if a file already exists, what happens to it if you try to open it as an output file?
When you open an output file you are creating the file on the disk. In most languages, if a file with the specified external name already exists when the file is opened, the contents of the existing file will be erased.
What is an input file?
a file that data is read from. It is called an input file because the program gets input from the file.
What is an output file?
a file that data is written to. It is called an output file because the program stores output in it.