7 Replies Latest reply on Mar 24, 2011 3:57 PM by -==cfSearching==-

    using randomAccessFile.readLine()

    rgurganus

      I'm in CF8, and so can't take advantage of the new I/O options in CF9.  So I'm using

       

      <cfset variables.randomAccessFile = createObject("java", "java.io.RandomAccessFile")>

      <cfset line = variables.randomAccessFile.readLine()>

       

      which works fine, until I want to do something like jump ahead to the 10,000th line.  I can put the readline() in a loop and count up to the line needed, but this is causing it to timeout.  Is there a single command something like seekLine(10000)?  I see that there is for seeking a position, character by character, but not that I can find for seeking lines.

       

      Thanks.

        • 1. Re: using randomAccessFile.readLine()
          -==cfSearching==- Level 4

          I'm in CF8, and so can't take advantage of the new I/O

          options in CF9. 

           

          What new options are you referring to?

           

          seekLine(10000)?  I see that there is for seeking a

          position, character by character, but not that I can find

          for seeking lines.

           

          There is no method for seeking by line. It is either jump to a specific position or read the lines one at a time. 

           

          Try a BufferedReader for comparison. Might be faster than RAF.

          • 2. Re: using randomAccessFile.readLine()
            rgurganus Level 1

            In CF 9, the CFLOOP with the "FILE" input, or functions like FileReadLine(), though this may just be a CF wrapper for the same Java function.

             

            Thanks for the suggesiton.  I did just find an article that does a comparison of BufferedReader and CFHTTP to read a file to a auery, and it says the latter is much faster.  So maybe I'll give this a try.

            • 3. Re: using randomAccessFile.readLine()
              -==cfSearching==- Level 4

              In CF 9, the CFLOOP with the "FILE" input, or functions

              like FileReadLine(), though this may just be a CF wrapper

              for the same Java function.

               

              Those were added in CF8, not CF9.

               

              Thanks for the suggesiton.  I did just find an article

              that does a comparison of BufferedReader and CFHTTP to read

              a file to a auery, and it says the latter is much faster. 

              So maybe I'll give this a try.

               

              So what is your ultimate goal, importing a text file into a database? If so most have import tools that are faster than looping. Such as bulk insert in ms sql.

              1 person found this helpful
              • 4. Re: using randomAccessFile.readLine()
                rgurganus Level 1

                So they are actually in CF8.  I looked but must not have been looking in the right place.

                 

                I'm importing a file, but through a web interface.  So me doing it through the server doesn't help.

                 

                So I'll do some tests between CFHTTP, randomAccessFile, and CFLOOP-FILE to see which wins.  Thanks.

                • 5. Re: using randomAccessFile.readLine()
                  rgurganus Level 1

                  In case anyone is interested...  I setup a side by side comparison, using CFHTTP (to a query, and then looping the query), RandomAccessFile, and CFLOOP-FILE to read a text file of 650,000 lines, each iterating record by record beginning to end, and captured the timestamps before and after.

                   

                  RAF = 1 minute 47 seconds

                  CFHTTP = 37 seconds

                  CFLOOP = 1 second (yes, only 1)

                   

                  I did a MOD on the record number, and outputed a few numbers inside the loop, just to prove to myself that it was actually iterating.

                  • 6. Re: using randomAccessFile.readLine()
                    -==cfSearching==- Level 4

                    I'm importing a file, but through a web interface.  So me

                    doing it through the server doesn't help.

                     

                    As long as you can pull down the file locally, you can import it into a database. Usually running one query per line is what takes the most time/resources.

                    • 7. Re: using randomAccessFile.readLine()
                      -==cfSearching==- Level 4

                      In case anyone is interested...  I setup a side by side

                      comparison

                       

                      Interesting. What about BufferedReader? Not that you need it with CF8, but I am curious as I suspect that is what the I/O tags/functions use for "read" mode internally.