[Newbies] reading lines from textfiles on Linux
Charles D Hixson
charleshixsn at earthlink.net
Mon May 15 22:13:51 UTC 2006
I'm having a lot of trouble trying to read in one line of text on a
| fil lin |
fil := CrLfFileStream new.
fil open: 'aising/data/technologies.csv' forWrite: False.
Transcript cr; show: (fil).
Transcript cr; show: 'LineEndConvention = '; show: fil lineEndConvention.
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'
[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