| 1 |
// test binary write + read |
| 2 |
me.dir() + "01-file-io.bin" => string filename; |
| 3 |
|
| 4 |
// writer |
| 5 |
FileIO f; |
| 6 |
f.open( filename, FileIO.BINARY | FileIO.WRITE ); |
| 7 |
// read |
| 8 |
f.write(1, IO.INT16); |
| 9 |
f.write(2, IO.INT16); |
| 10 |
f.write(3, IO.INT16); |
| 11 |
// close |
| 12 |
f.close(); |
| 13 |
|
| 14 |
// reader |
| 15 |
FileIO g; |
| 16 |
g.open( filename, FileIO.BINARY | FileIO.READ ); |
| 17 |
// ensure it's ok |
| 18 |
if( !g.good() ) |
| 19 |
{ |
| 20 |
cherr <= "can't open file: for reading..." <= IO.newline(); |
| 21 |
me.exit(); |
| 22 |
} |
| 23 |
// read |
| 24 |
g.readInt( IO.INT16 ) => int x; |
| 25 |
g.readInt( IO.INT16 ) => int y; |
| 26 |
g.readInt( IO.INT16 ) => int z; |
| 27 |
// close |
| 28 |
g.close(); |
| 29 |
|
| 30 |
// verify |
| 31 |
if( x == 1 && y == 2 && z == 3 ) |
| 32 |
<<< "success" >>>; |