August 1999
Intermediate to advanced
1488 pages
72h 53m
English
file.getLength()
The getLength() of the File object returns the number of characters in a text file or the number of bytes in a binary file. If the method is unsuccessful, –1 is returned.
Listing 8.78 opens a file for reading and another file for writing. The getLength() method is used in a for loop to determine when to stop reading from the file.
<SERVER> // Open the files var myLog = new File("/data/logs/today.log"); var mySummary = new File("/data/logs/summary.log"); myLog.open("r"); mySummary.open("w"); // Write the contents of the log file to the page for(var i = 0; i <= myLog.getLength(); i++){ myBytes = File.byteToString(myLog.readByte()); ... |
Read now
Unlock full access