Reads a single byte value from an open file. The parameter is the integer file handle returned by OPENIN, OPENOUT, or OPENUP. The function returns the next byte as an integer in the range 0–255.
Examples
REM Read a file byte by byte
fh = OPENIN("/data/example.bin")
IF fh < 0 THEN
PRINT "Could not open file"
END
ENDIF
REPEAT
b = READ(fh)
IF EOF(fh) = 0 THEN PRINT "Byte = "; b
UNTIL EOF(fh) = 1
CLOSE fh
REM Read first three bytes
fh = OPENIN("/data/file.bin")
b1 = READ(fh)
b2 = READ(fh)
b3 = READ(fh)
PRINT b1; ","; b2; ","; b3
CLOSE fh
Notes
- Returns an integer 0–255.
- Use EOF to detect end-of-file. If called at EOF, behaviour is undefined without checking.
- For reading full lines as strings, use READ$.
- File handle must be closed with CLOSE.
See also: READ$ · OPENIN · OPENUP · CLOSE · EOF