Michael Husmann <michael.husmann / teleatlas.com> writes: > Thank you for the hint. But my question was not how to determine the > number of lines or the file length but to read a file > efficiently. This becomes interesting when you are working on large > files. Getting a look at Python. There it possible to read the file > in chunks of bytes. That increases speed dramatically. The same > feature would be helpful in Ruby. ------------------------------------------------------------- IO#sysread ios.sysread( anInteger ) -> aString ------------------------------------------------------------------------ Reads anInteger bytes from ios using a low-level read and returns them as a string. Do not mix with other methods that read from ios or you may get unpredictable results. Raises SystemCallError on error and EOFError at end of file. f = File.new("testfile") f.sysread(16) #=> "This is line one" and ---------------------------------------------------------------- IO#read ios.read( [anInteger] ) -> aString or nil ------------------------------------------------------------------------ Reads at most anInteger bytes from the I/O stream, or to the end of file if anInteger is omitted. Returns nil if called at end of file. f = File.new("testfile") f.read(16) #=> "This is line one" You can also find out the underlying blocksize using File.stat(name).blksize. Also, the ftools package contains a bunch of useful file moving, copying, and creating routines. Also, you can read the source for hints on efficient file IO. Dave