File handling Flashcards

(4 cards)

1
Q

What is a file and its rules?

A
  • A serial file (simplest file) is one in which data has been stored in the order in which it occurred.
  • To write to a file, either create a new file or append to the end of the file line by line.
  • To search in a file (read), start at the top of the file and read line by line until you find what you are looking for or reach the end of the file.
  • Data cannot be deleted or changed in the file directly. Instead create a new file and copy all the lines (inserting any changes), except the lines to be deleted, to the new file.
  • You cannot read or write to a file at the same time.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

How to read one line from a file in pseudocode?

A

myFile = openRead(“test.txt”)
line = myFile.readLine()
myFile.close()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

How to print all lines from a file in pseudocode?

A

myFile = openRead(“sample.txt”)
while NOT myFile.endOfFile()
print(myFile.readLine())
endwhile
myFile.close()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How to write one line to a file in pseudocode?

A

myFile = openWrite(“sample.txt”)
myFile.writeLine(“Hello World”)
myFile.close()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly