Beginners Question Regarding File I/O

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Beginners Question Regarding File I/O

Roger Gilliar
The following code is blocking the while UI until the whole file is read. Why ? Is there a better way to process large text files ?

Regards
  Roger

|stream inRec|

stream := FileStream readOnlyFileNamed: '/Users/roger/Desktop/d001.txt' .

[stream atEnd] whileFalse: [
      inRec := stream upTo: Character cr.  
        Transcript show: '@'.  
].

stream close.
Reply | Threaded
Open this post in threaded view
|

Re: Beginners Question Regarding File I/O

Sven Van Caekenberghe
Roger,

On 02 May 2012, at 21:01, Roger Gilliar wrote:

> The following code is blocking the while UI until the whole file is read. Why ?

There is only one UI thread. You make it do something that takes a long time, thus the whole UI is waiting.

> Is there a better way to process large text files ?
>
> Regards
>  Roger
>
> |stream inRec|
>
> stream := FileStream readOnlyFileNamed: '/Users/roger/Desktop/d001.txt' .
>
> [stream atEnd] whileFalse: [
>     inRec := stream upTo: Character cr.  
> Transcript show: '@'.  
> ].
>
> stream close.

Yes, try:

[ |stream inRec|

  stream := FileStream readOnlyFileNamed: '/Users/roger/Desktop/d001.txt' .

  [stream atEnd] whileFalse: [
    inRec := stream upTo: Character cr.  
        Transcript show: '@'.  
  ].

  stream close ] fork.

Sven