[gambit-list] reading file into string / length of file

Marc Feeley feeley at iro.umontreal.ca
Sun Jun 28 23:19:17 EDT 2009


On 28-Jun-09, at 10:46 PM, lowly coder wrote:

> I want to read a file into a string. After I open it up, is there a  
> way to get the length of the file? (or even before I open it up?)
>
> I see that we have read-substring and read-u8vector
>
> Currently, the best solution appears to be ... do a read-u8vector on  
> it, get it's string length, then re-open the file and do a read- 
> substring on it ... surely there's something more elegant. :-)

% gsi
Gambit v4.4.4

 > (file-info-size (file-info "test.txt"))
53
 > (call-with-input-file "test.txt" (lambda (p) (read-line p #f)))
"the read-line procedure is\ndocumented in the manual!\n"
 > (help read-line)

Marc




More information about the Gambit-list mailing list