open Method

Class: IO

Description

This method opens a device based on the fileName and directory IO class properties. If you do not define the directory property, the device defaults to the file name stored in the spool directory.

 

If the timeout property is the empty string, the open method waits until it succeeds. Otherwise, it waits until it succeeds or until the timeout expires, whichever comes first. If the timeout expires, an exception is thrown.

 

The values of the openParams and recordSize properties is used as assigned by the program. Improper values causes a %PSL-E-IOOPEN exception.

 

The open method sets the input character set and output character set based on the values of the charsetName, charsetElemName, and charsetElemType properties, and the context in which the open occurs. The following algorithm is used:

Syntax

do objectName.open()

Parameters

None

However, the fileName and openParams IO class properties must be defined prior to using this method.

Returns

None

Throws

Error

Cause

%PSL-E-IOOPEN

The open failed.

When Became Available

v6.4

Example

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

set io.directory = ”/unix_directory/spool”

set io.fileName = ”TEST.txt”

set io.openParams = ”NEWV/WRITE”

set io.timeout = 5

catch ioxcpt {

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

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

 

      write "Open failed: ", ioxcpt.type, !

}

do io.open()

type String TEXT

set TEXT = ”This is a file created using IO class methods.”

do io.write(TEXT)

do io.close()

 

* The value of the directory property must be a valid directory path.