Delphi: Alternative to using Reset/ReadLn for text file reading

后端 未结 7 1234
时光取名叫无心
时光取名叫无心 2020-12-14 11:10

i want to process a text file line by line. In the olden days i loaded the file into a StringList:

slFile := TStringList.Create();
slFile.LoadFr         


        
7条回答
  •  暗喜
    暗喜 (楼主)
    2020-12-14 11:49

    What I do is use a TFileStream but I buffer the input into fairly large blocks (e.g. a few megabytes each) and read and process one block at a time. That way I don't have to load the whole file at once.

    It works quite quickly that way, even for large files.

    I do have a progress indicator. As I load each block, I increment it by the fraction of the file that has additionally been loaded.

    Reading one line at a time, without something to do your buffering, is simply too slow for large files.

提交回复
热议问题