IFSFileInputStream

The IFSFileInputStream class represents an input stream for reading data from a file on the AS/400. As in the IFSFile class, methods exist in IFSFileInputStream that duplicate the methods in FileInputStream from the java.io package. In addition to these methods, IFSFileInputStream has additional methods specific to the AS/400. The IFSFileInputStream class allows a Java program to do the following:

  • Open a file for reading. The file must exist since this class does not create files on the AS/400.
  • Open a file for reading and specify the file sharing mode.
  • Determine the number of bytes in the stream.
  • Read bytes from the stream.
  • Skip bytes in the stream.
  • Lock or unlock bytes in the stream.
  • Close the file.

As in FileInputStream in java.io, this class allows a Java program to read a stream of bytes from the file. The Java program reads the bytes sequentially with only the additional option of skipping bytes in the stream.

The following example shows how to use the IFSFileInputStream class.

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

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

                       // Determine the number of bytes in
                       // the file.
     int available = aFile.available();

                       // Allocate a buffer to hold the data
     byte[] data = new byte[10240];

                       // Read the entire file 10K at a time
     for (int i = 0; i < available; i += 10240)
     {
         aFile.read(data);
     }

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

In addition to the methods in FileInputStream, IFSFileInputStream 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 ]