IFSFileOutputStream

The IFSFileOutputStream class represents an output stream for writing data to a file on the AS/400. As in the IFSFile class, methods exist in IFSFileOutputStream that duplicate the methods in FileOutputStream from the java.io package. IFSFileOutputStream also has additional methods specific to the AS/400. The IFSFileOutputStream class allows a Java program to do the following:

  • Open a file for writing. If the file already exists, it is replaced. Also available is a constructor that takes a boolean argument that specifies whether the contents of an existing file have been appended.
  • Open a file for writing and specifying the file sharing mode.
  • Write bytes to the stream.
  • Commit to disk the bytes that are written to the stream.
  • Lock or unlock bytes in the stream.
  • Close the file.

As in FileOutputStream in java.io, this class allows a Java program to sequentially write a stream of bytes to the file.

The following example shows how to use the IFSFileOutputStream class.

                       // Create an AS400 object
     AS400 sys = new AS400("mySystem.myCompany.com");

                       // Open a file object that
                       // represents the file.
     IFSFileOutputStream aFile =
                   new IFSFileOutputStream(sys,"/mydir1/mydir2/myfile");

                       // Write to the file
     byte i = 123;
     aFile.write(i);

                       // Close the file.
     aFile.close();

In addition to the methods in FileOutputStream, IFSFileOutputStream gives the Java program the following options:

  • Locking and unlocking bytes in the stream. See IFSKey for more information.
  • Specifying a sharing mode when the file is opened. See sharing modes for more information.


[ Legal | AS/400 Glossary ]