Class File

Introduction

This class wraps file I/O. Currently, this class only supports simple sequential file manipulation, but it may be extended in a future version.

Contents

  1. Introduction
  2. Contents
  3. Explanation of symbols used
  4. Member reference
    1. channel - retrieve the file's channel
    2. Close - Close the file
    3. Display - display text to the file
    4. mode - retrieve the file's open mode
    5. name - retrieve the file's name
    6. open - create a File object
    7. ReadLine - read sequentially from the file
    8. ReadLines - read all remaining lines from the file
    9. WriteLine - write sequentially to the file

Explanation of symbols used

Words in italics indicate an instance of a class. The word corresponds to the class name, except where more than one instance is represented in the same statement. In that case a number (2, 3, etc.) is appended to the class name.

Words in normal typeface are to be taken literally (required punctuation, class name in a static reference, method name, etc.)

The symbol => is used to separate an expression (on the left) from its return value (on the right).

An ellipsis (...) indicates that the previous argument may be repeated any number of times. The description will indicate whether one instance is required.

Member reference

property channel

file.channel => int
This read-only property yields the channel number used for I/O.

method Close

file.Close()

This method closes the file. It is called automatically by the destructor, but on .NET you may wish to call it explicitly, because you cannot know when the destructor will be invoked. If called more than once, no error results.

If the UI Toolkit was used to open this file (see Open), then the UI Toolkit routine U_CLOSE will be used to close it.

method Display

file.Display(a)

This method writes raw text to file, without any line terminator.

If the mode of the file is incompatible with a variable-length write, or if some other error occurs, a catchable exception will result.

property mode

file.mode => a
This read-only property yields the mode used to open the file.

property name

file.name => a
This read-only property yields the name of the file as passed to the constructor.

static method open, constructor

File.Open(a) => file
File.Open(a, a2) => file
new File(a) => file
new File(a, a2) => file

Instantiates a new File object and opens the file named a. If a2 is passed, it specifies the I/O mode. Otherwise, "I" is assumed.

If the UI Toolkit is active, this method uses U_OPEN to open the file, and U_GBLCHN to prevent the UI Toolkit from closing it before this object goes out of scope. If the UI Toolkit is not active, this method seeks out an open channel and opens it directly.

If an error occurs when opening the file, a catchable exception will result.

method ReadLine

file.ReadLine() => string
This method obtains a line of input from the file. If an error occurs (other than EOF), a catchable exception results. If EOF is encountered, string is returned ^null. Otherwise, string is returned with the line of text read.

method ReadLines

file.ReadLines() => ls
This method reads all remaining lines of input from file, and returns an ls in which each member is a Var containing a line of text.

method WriteLine

file.WriteLine(object)

This method writes sequentially to file. If object is an ArrayList (or derived from ArrayList -- e.g., ls), then each member's string representation (obtained by calling its ToString() method) is output as a separate line. For any other type of object or primitive (a, int, decimal), the string representation of that argument is output as a separate line.

If the mode of the file is incompatible with a sequential write, or if some other error occurs, a catchable exception will result.