Difference between revisions of "FileHandle"

From MiniScript Wiki
Jump to navigation Jump to search
(Created page with "In Mini Micro and command-line MiniScript, the <c>FileHandle</c> class is a small class that represents a file that has been opened for reading, writing, or updating v...")
 
m
 
Line 13: Line 13:
 
| position || current read/write position, in bytes from the beginning of the file
 
| position || current read/write position, in bytes from the beginning of the file
 
|-
 
|-
| atEnd || true when the current read/write position is at the end of the file
+
| [[FileHandle.atEnd|atEnd]] || true when the current read/write position is at the end of the file
 
|-
 
|-
 
| write ''s'' || write a string to the file (in UTF-8 format)
 
| write ''s'' || write a string to the file (in UTF-8 format)

Latest revision as of 18:22, 9 January 2021

In Mini Micro and command-line MiniScript, the FileHandle class is a small class that represents a file that has been opened for reading, writing, or updating via file.open.

It provides the following methods:

Method Purpose
isOpen true if the file is still open; false after close has been called
close close the file, flushing any changes to disk
position current read/write position, in bytes from the beginning of the file
atEnd true when the current read/write position is at the end of the file
write s write a string to the file (in UTF-8 format)
writeLine s write a string to the file (in UTF-8 format), followed by a line break
read return the rest of the file, as a string (assumes UTF-8 format)
readLine return text from the current position to the next line break (assumes UTF-8)

Note that the write, writeLine, read, and readLine functions all advance the file position.