File Handling Flashcards
What is file handling?
How a program can access data and change data stored in an external file.
What’s a benefit of accessing external files?
Accessing external files make programs more useful and powerful.
What’s the first step to using a file?
To open it.
How can you open a file?
Using an open command and assigning it to a variable.
What is openRead?
- will open the file in read mode
- means you can read data from the file into your program
What is openWrite?
- will open the file in write mode
- allows you to write data from your program to the file
What happens once the file is opened?
The program will start reading or writing it from the beginning. As this happens the program keeps its place in the file. (like a cursor).
What happens once you’ve finished reading or writing to a file?
Should always close the file using close().
What happens if you forget to close an opened file?
Then the file can remain locked and prevent others from editing it.
How can you write lines of text to file once it’s opened?
- using writeLine()
If he file contains text when you’re using writeLine what happens?
It’ll overwrite what is currently there.
Where is the writeLine command called in a program?
On the variable that stores the external file.
What will the writeLine do after it’s called?
Automatically move onto the next line.
You can read lines of text from a file using what?
readLine()
What does the command endOfFile() do?
It returns true when the ‘cursor’ is at the end of the file. It’s main use is to signify when a program should stop reading a file.