Text files contain text that is in lines. There is no other structure.

Example 1 shows how to read a text file in pseudo-code.

Example 1
file ← OPENREAD("students.txt")
FOR n ← 0 TO LEN(file)-1
  line ← file.READLINE()
OUTPUT line
ENDFOR
file.CLOSE()

Example 2 shows how to write to a text file in pseudo-code.

Example 2
file ← OPENWRITE("students.txt")
FOR n ← 0 TO 9
  name ← USERINPUT
  file.WRITELINE(name)
ENDFOR
file.CLOSE()

Comma-separated value (CSV) files provide a bit more structure. In each line, the fields are separated by commas. They are handled exactly the same way as regular text files.



What are the disadvantages of using CSV files instead of regular text files?

They need more string processing and manipulation when reading and writing.