設定游標位置

一個開啟檔案具有一個游標。游標指向要讀取、更新或刪除的記錄。最先開啟某檔案之後,游標會指向該檔案的開頭。檔案的開頭是在第一筆記錄前面。

使用下列方法來設定游標位置:

下面範例說明如何使用 positionCursorToFirst() 方法來定位游標。

     // 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);