Defined in File.sc.
This class encapsulates reading and writing to a file.
= myFile (File new:) (if (newFile name: "myfile.txt" open: fOPENFAIL) ; Read stuff from file, etc... ) ; Close the file. (newFile close: dispose:)
Defined in File:
Opens the file in one of the following modes:
- Opens the file. If the file doesn’t exist, it is created.
- Opens the file and fails if it doesn’t exist.
- Opens the file, deleting any previous content it had.
Parameters: openMode (number) – fOPENCREATE, fOPENFAIL or fCREATE. If not specified, fOPENCREATE is used. Returns: The file object if successful, otherwise NULL.
Reads a text string from the file.
- buffer (string) – The buffer into which the text is placed.
- maxSize (number) – The buffer size.
The number of characters read.
Writes a text string (or multiple text strings) to the file.
Parameters: buffer (string) – Buffer containing the string. Multiple strings may be provided.
Writes data to the file.
- buffer (heapPtr) – Buffer of data to be written.
- count (number) – The number of bytes in the buffer.
The number of bytes written, or NULL if it failed.
Reads data into a buffer.
- buffer (heapPtr) – Buffer into which the data will be read.
- size (number) – The size in bytes in the buffer.
The number of bytes read, or NULL if it failed.
Seeks to a position in the file.
- offset (number) – Positive or negative offset.
- whence (number) – 0 to seek from the beginning, 1 to seek from the current position, or 2 to seek from the end.
Closes the file.
Deletes the file.