Built-in Functions
Structures
Built-in Variables and Constants
Conventions
Exchanges
File.eof
Check if the file pointer has reached the end of file.
eof()Examples
Read file line by line until end of file.
javascript
function main() {
let file = os.open("data.txt", "r")
let lineCount = 0
while (!file.eof()) {
let line = file.getline()
if (line !== undefined) {
lineCount++
Log("Line", lineCount + ":", line)
}
}
Log("Total lines:", lineCount)
file.close()
}Returns
| Type | Description |
bool | Returns true if end of file has been reached, otherwise returns false. |
See Also
Remarks
Used to determine whether all content has been read when reading a file. It returns true only after a read has hit the end of file, e.g. getline() returned undefined, read(size) got no data, or read() without arguments read the rest of the file; seek() resets it to false.