The IFSRandomAccessFile class represents a file on the server for reading and writing data.
The Java™ program can read and write data sequentially or randomly. As in IFSFile, methods exist in IFSRandomAccessFile that duplicate the methods in RandomAccessFile from the java.io package. In addition to these methods, IFSRandomAccessFile has additional methods specific to the iSeries™ server. Through IFSRandomAccessFile, a Java program can do the following:
In addition to the methods in java.io RandomAccessFile, IFSRandomAccessFile gives the Java program the following options:
The following example shows how to use the IFSRandomAccessFile class to write four bytes at 1K intervals to a file.
// Create an AS400 object. AS400 sys = new AS400("mySystem.myCompany.com"); // Open a file object that represents // the file. IFSRandomAccessFile aFile = new IFSRandomAccessFile(sys,"/mydir1/myfile", "rw"); // Establish the data to write. byte i = 123; // Write to the file 10 times at 1K // intervals. for (int j=0; j<10; j++) { // Move the current offset. aFile.seek(j * 1024); // Write to the file. The current // offset advances by the size of // the write. aFile.write(i); } // Close the file. aFile.close();