Libraries.Data.Formats.SeparatedValueFileReader Documentation

Inherits from: Libraries.System.FileReader, Libraries.System.Blueprints.FileReaderBlueprint, Libraries.Language.Object

Summary

Actions Summary Table

ActionsDescription
Close()When we open a file for reading, it is marked by the operating system as being in use by our application.
Compare(Libraries.Language.Object object)This action compares two object hash codes and returns a CompareResult.
Equals(Libraries.Language.Object object)This action determines if two objects are equal based on their hash code values.
GetHashCode()This action gets the hash code for an object.
IsAtEndOfFile()
OpenForRead(Libraries.System.File file)Open a file for sequential reading.
Read(integer numberOfBytes)This action reads the specified number of bytes after our current position.
Read()This action reads all of the contents of our file from the current position.
ReadLine()
ReadLines()

Actions Documentation

Close()

When we open a file for reading, it is marked by the operating system as being in use by our application. To make it possible for other files to use this file at a later point in time, it is necessary to tell the operating system when we are done with this file. To do this, we use the Close() action. We should call Close() as soon as we know that a file is no longer needed. If no file is open, Close() will do nothing. After Close() is called, a FileReader object is considered invalid, and no actions should be called on it, other than OpenForRead(), to open the same (or different) file.

Example Code

use Libraries.System.File
        use Libraries.System.FileReader

        // Open a file, read all the contents and close it.
        File f
        f:SetPath("To Do List.txt")
        FileReader reader
        reader:OpenForRead(f)

        output "Tim, your to do list says:"
        output reader:Read()
        
        // Close the file, as we no longer need it.
        reader:Close()

Compare(Libraries.Language.Object object)

This action compares two object hash codes and returns a CompareResult. The compare result is either larger if this hash code is larger than the object passed as a parameter, smaller, or equal.

Example Code

use Libraries.Language.Support.CompareResult
        Object o
        Object t
        CompareResult result = o:Compare(t)

Parameters

Return

Libraries.Language.Support.CompareResult: The Compare result, Smaller, Equal, or Larger.

Equals(Libraries.Language.Object object)

This action determines if two objects are equal based on their hash code values.

Example Code

use Libraries.Language.Object
        use Libraries.Language.Types.Text
        Object o
        Text t
        boolean result = o:Equals(t)

Parameters

Return

boolean: True if the hash codes are equal and false if they are not equal.

GetHashCode()

This action gets the hash code for an object.

Example Code

Object o
        integer hash = o:GetHashCode()

Return

integer: The integer hash code of the object.

IsAtEndOfFile()

Return

boolean

OpenForRead(Libraries.System.File file)

Open a file for sequential reading. By "sequential reading," it is meant that it is impossible to go backwards in the file--we must make progress toward the end of the file with each successive read. This is extremely useful for reading plain text documents, but is much less useful for reading binary files. Binary files should use the FileRandomAccess class.

Example Code

use Libraries.System.File
        use Libraries.System.FileReader

        // Open the file for reading.
        File f
        f:SetPath("homework.txt")
        
        // Read the first two lines and then be done.
        FileReader reader
        reader:OpenForRead(f)
        output reader:ReadLine()
        output reader:ReadLine()

        // Always close the file.
        reader:Close()

Parameters

Read(integer numberOfBytes)

This action reads the specified number of bytes after our current position. When we open a file, we start at the beginning--calling this action with a parameter of, for example, 2, would read the first two bytes of the file. If we perform some other reading action such as ReadLine(), and then call this action, the specified number of bytes will be read after our current position. If the number of bytes specified exceeds the end of the file, content up to the end of the file will be returned. If the end of the file has been reached before this action is called, an EndOfFileError will be raised.

Example Code

use Libraries.System.File
        use Libraries.System.FileReader

        // Open a file, output the first four bytes.
        File f
        f:SetPath("Settings.dat")
        FileReader reader
        reader:OpenForRead(f)
        output "The first four bytes are " + reader:Read(4)
        reader:Close()

Parameters

Return

text: the file contents we have read

Read()

This action reads all of the contents of our file from the current position. When we open a file, we start at the beginning--so calling this action immediately after opening a file will read the entire file. If we perform some other reading action, such as ReadLine(), and then call this action, we will receive all file contents after the point where we have read. If the end of file has already been reached before calling this action, an EndOfFileError will be raised.

Example Code

use Libraries.System.File
        use Libraries.System.FileReader

        // Open a file, read all of its contents to a text value and then  output the text value.
        File f
        f:SetPath("Settings.dat")
        FileReader reader
        reader:OpenForRead(f)
        text settings = reader:Read()

        output "The settings are:"
        output settings
        reader:Close()

Return

text: the file contents from our current position to the end of the file.

ReadLine()

Return

text

ReadLines()

Return

Libraries.Containers.Array