[Newbies] Re: reading lines from textfiles on Linux

Klaus D. Witzel klaus.witzel at cobss.com
Tue May 16 00:11:12 UTC 2006


Hi Charles,

on Tue, 16 May 2006 00:13:51 +0200, you <charleshixsn at earthlink.net> wrote:

> I'm having a lot of trouble trying to read in one line of text on a
> Linux system.

This is normal, Squeak likes apples more than anything else :-D

Have a look at the implementor of #concreteStream. I often implant  
CrLfFileStream there.

BTW: what release / image / platform are you using? CrLfFileStream should  
be O.K. for reading *nix files, I do that day-in-day-out.

/Klaus

> the commands:
> | fil lin |
> fil    :=    CrLfFileStream new.
> fil open: 'aising/data/technologies.csv' forWrite: False.
> Transcript cr; show: (fil).
> fil    ascii.
> Transcript cr; show: 'LineEndConvention = '; show: fil lineEndConvention.
> fil reopen.
> lin    :=    fil nextLine.
> Transcript cr; show: 'lin 1 = '; show: lin.
>
> Fail at the attempt to reopen.  (Or, alternatively, either an attempt to
> "fil position: 0" or "fil position: 1".
> If I don't test the line end convention, the entire file is read into
> the first line.  If I do the test, the result is that the protocol is
> "lf" (which seems the right answer).  If I open the file in a standard
> text editor, it looks correct, and has 43 lines + an empty 44th line
> (that I believe is created in th editor).
>
> I at first tried to copy the example from the "cookbook" exactly:
> file := FileStream fileNamed: 'test.txt'.
> [file atEnd] whileFalse:
> [line := file nextLine. "Process the line"]
>
> (well, I used StandardFileStream rather than FileStream, and I changed
> the file opening to
> tmpFile    :=    StandardFileStream open: 'aising/data/technologies.csv'
> forWrite: False.
>     [tmpFile atEnd]    whileFalse:
>         [    temp    :=    tmpFile nextLine.
>
> When everything in the file ended up read into the first line, I started
> trying alternates...so far without success.
>
> Any suggestions?  I'd try using the code without modifications, but my
> image doesn't appear to *have* a FileStream class.




More information about the Beginners mailing list