| | 1 | #charset "iso-8859-1" |
| | 2 | |
| | 3 | #include <tads.h> |
| | 4 | #include <file.h> |
| | 5 | |
| | 6 | main(args) |
| | 7 | { |
| | 8 | local f; |
| | 9 | |
| | 10 | /* create a text file */ |
| | 11 | f = File.openTextFile('file1.txt', FileAccessWrite, 'iso-8859-1'); |
| | 12 | |
| | 13 | /* write some data */ |
| | 14 | f.writeFile('This is some data for the file.\n' |
| | 15 | + 'Here is the second line of text.\n' |
| | 16 | + 'A blank line follows this one.\n' |
| | 17 | + '\n' |
| | 18 | + 'Okay, here are a few latin-1 characters: “Åéîõü”\n' |
| | 19 | + 'This is the last line!\n'); |
| | 20 | |
| | 21 | /* done - close the file */ |
| | 22 | f.closeFile(); |
| | 23 | |
| | 24 | /* now read the file back and display its contents */ |
| | 25 | f = File.openTextFile('file1.txt', FileAccessRead, 'iso-8859-1'); |
| | 26 | |
| | 27 | /* read from the file until done */ |
| | 28 | for (local linenum = 1 ; ; ++linenum) |
| | 29 | { |
| | 30 | local txt; |
| | 31 | |
| | 32 | /* read another line - stop at eof */ |
| | 33 | if ((txt = f.readFile()) == nil) |
| | 34 | break; |
| | 35 | |
| | 36 | /* show it */ |
| | 37 | "<<linenum>>:<<txt>>"; |
| | 38 | } |
| | 39 | |
| | 40 | "\<\<EOF>>\b"; |
| | 41 | } |