File.eof()

NES2+Syntax

							file.eof()

Description

The eof() method of the File object returns true if the position of the pointer within the file is past the end of the file. It returns false otherwise.

Example

Listing 8.74 reads a file and writes its contents to the page until the end of the file is found with the eof() method.

Listing 8.74 Reading a File Until You Come to the End of It
<SERVER>

// Open a log file for reading
var myLog = new File("/data/logs/today.log");
myLog.open("r");

// Write the contents of the log file to the page
while (!myLog.eof()){
  myBytes = File.byteToString(myLog.readByte());
  write(myBytes);
}

// Close the file
myLog.close();

</SERVER>
						

Get Pure JavaScript now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.