read Method

Class: IO

Description

This method reads a record from the device defined by the fileName and directory IO class properties. To use this method, the openParams property must contain READ.

 

If the charsetName property contains a non-empty value, then characters would have been converted from IO.charsetName to Runtime.charsetName.

Syntax

set PRIM = objectName.read(errorType)

Parameters

errorType

A number identifying an error plus an error description. For example:

0 — No error

1 — End of file

2 — Device device not open

This parameter is optional. The default ErrorType is the variable ETYP.

As of Profile v7.0, this parameter is deprecated. Use catch blocks to deal with all IO-related exceptions.

Returns

The value read.

Throws

Error

Cause

%PSL-E-IONOTOPEN

IO.open has not been called before (i.e., the device has not been opened).

%PSL-E-IOEOF

Reached the end of file.

%PSL-E-IOOTHER

Other exception. The Error.description and Error.context may contain additional information.

When Became Available

v6.4

Example

type IO io = Class.new(“IO”)

set io.directory = ”/unix_directory/spool”

set io.fileName = ”READTEST.txt”

set io.openParams = ”READ”

 

catch iox {

      // if device has been opened, close it

      if io.device'="" do io.close()

      // if not an IO exception, it's not for us

      if iox'["%PSL-E-IO" throw iox

      // handle the IO exceptions

      if iox["IOOPEN" write "Open failed", ! quit

      if iox["IOEOF"  write "Reached end of file", ! quit

      write "unexpected IO error '", iox.type, "'", !

}

do io.open()

type String PART1,PART2,REC

 

for  set REC = io.read() do {

   set PART1 = REC.piece(“,”,1)

   set PART2 = REC.piece(“,”,2)

}

 

*The value of the device property must be a valid file that can be accessed by the user.