Input/output classes

 

Overview

The family of stream classes (stream, outStream, inStream) is used to manage input/output.  Three predefined instances of the "outStream" class correspond to the standard exits (stdOut, stdErr, stdFile).

 

The "Stream" class

The "Stream" class is abstract and provides the following services.

 

The ... method

is used to ...

boolean isFile(inString fileName)

test whether a file exists.  Returns true if "fileName" is a normal file which exists, and false in all other cases, including the case where "fileName" is a directory or in the case of E/S errors.

boolean isDirectory(in String directoryName)

test whether a directory exists.  Returns true if "directoryName" is a directory or a network letter ("C:") which exists, and false in all other cases.

 

 

The "outStream" class

The "outStream" class represents output flows.  Its methods are as follows:

 

The ... method

is used to ...

boolean open(in String pFileName, in boolean pAppendMode)

open the file indicated by "name".  If "pAppendMode" is true, this operation does not reset the file to zero and prepares to write in append mode. If pAppendMode is false, this operation overwrites the previous contents and prepares to write in the file.  If the file does not exist, it is created.  If the file cannot be opened, false is returned. 

The "pFileName" parameter is an absolute or relative path.

The second parameter (pAppendMode) is optional.  Its default value is false.

write (in basic_class p1

in basic_class p2, ...)

write the list of primitive values supplied as parameters.

close ()

close the file.

existFile (in String FileName, out boolean answer)

test the existence of the file by its name.

 

 

The "inStream" class

The "inStream" class represents in files.  It is used to read the dataflow stored in the file.  Its methods are as follows:

 

The ... method

is used to ...

boolean open(in String FileName)

open the file with the indicated name. The file must exist.

read (in String buffer)

read the file in the "buffer".

close ()

close the file.

existFile (in String FileName,out boolean answer)

test the existence of a file, using its name.

 

 

Example

We are going to write different values in a file.

 

boolean b=true;

int i= 23;

outStream MyFile;

MyFile.open("EXIT");

MyFile.write ("i == ",i, " b == ", b, NL);

MyFile.close();

 

The result in the "EXIT" file is as follows:

 

i == 23 b == true

 

Note:      The "inStream" class combined with "eval" is used to load the formatted data.

 

 

Predefined output

The default output linked to the predefined output corresponds to the output window if J execution is launched in Objecteering.

 

The ... exit

corresponds to ...

StdOut

the predefined output for messages (screen or output window).

StdErr

the predefined output for error messages.