From: Tom Payne Date: 2002-09-11T01:14:25+09:00 Subject: Re: Reading a specific offset into a file. In article <9ba6a8da.0209100651.449803e8@posting.google.com>, Khurram wrote: > What is an easy way to read a specific byte offset of a file? Right > now I'm going through and using the .getc function until I get to the > specific offset I need. This is very tedious because I just have a > list of .getc calls. THere must be an easier way to do this? > > Right now I'm doing this in order to get to 4th byte in file: > ------------------------------- > a = File.open("example.dat") > a.getc > a.getc > a.getc > a.getc > byte_4 = a.getc > a.close > ------------------------------- > Thanks, > > - Khurram You could use a loop: a = File.open("example.dat") 4.times { a.getc } byte_4 = a.getc a.close ;-) Of course, IO#seek is what you really need, or possibly even IO#read/String#unpack. T