An open file has a cursor. The cursor points to the record to be read, updated, or deleted. When a file is first opened the cursor points to the beginning of the file. The beginning of the file is before the first record. Use the following methods to set the cursor position:
The following example shows how to use the positionCursorToFirst() method to position the cursor.
// Create an AS400 object, the file exists on this // server. AS400 sys = new AS400("mySystem.myCompany.com"); // Create a file object that represents the file SequentialFile myFile = new SequentialFile(sys, "/QSYS.LIB/MYLIB.LIB/MYFILE.FILE/%FILE%.MBR"); // Assume that the AS400FileRecordDescription class // was used to generate the code for a subclass of // RecordFormat that represents the record format // of file MYFILE in library MYLIB. The code was // compiled and is available for use by the Java // program. RecordFormat recordFormat = new MYFILEFormat(); // Set the record format for myFile. This must // be done before invoking open() myFile.setRecordFormat(recordFormat); // Open the file. myFile.open(AS400File.READ_WRITE, 1, AS400File.COMMIT_LOCK_LEVEL_NONE); // I want to delete the first record of the file. myFile.positionCursorToFirst(); myFile.deleteCurrentRecord(); .... // Close the file since I am done using it myFile.close(); // Disconnect since I am done using // record-level access sys.disconnectService(AS400.RECORDACCESS);