open file

Scala file reading performance: Line counting algorithms

Out of curiosity about Scala’s file-reading performance, I decided to write a “line count” program in Scala. One obvious approach was to count the newline characters in the file:

AppleScript code to read file contents into a list (array)

I just ran into a situation where I wanted to use AppleScript to read some file contents into a list/array, and came up with the following code:

set theFile to "/Users/al/Projects/Scala/Sarah/scripts/thank_you.data"
set fileHandle to open for access theFile
set thankYous to paragraphs of (read fileHandle)
close access fileHandle

I can confirm that this code works on my Mac OS X 10.6.8 system. The variable thankYous is a list/array that contains the lines from my file.