www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Read a text file in any position.

reply Giovanni Di Maria <calimero22 yahoo.it> writes:
Hi All
I have a text file like this:

111111
222222
333333
444444
555555
666666
777777
......

I execute these functions:

i = archive.readln();
i = archive.readln();
i = archive.readln();
i = archive.readln();

so "i" is 444444.

Is there a method to move the pointer of file to beginning of 
file or to any position (for example back to 2nd row), without to 
close the file?

Thank you very much.
Regards
Giovanni
Jan 18 2019
parent reply bauss <jj_1337 live.dk> writes:
On Friday, 18 January 2019 at 08:10:25 UTC, Giovanni Di Maria 
wrote:
 Hi All
 I have a text file like this:

 111111
 222222
 333333
 444444
 555555
 666666
 777777
 ......

 I execute these functions:

 i = archive.readln();
 i = archive.readln();
 i = archive.readln();
 i = archive.readln();

 so "i" is 444444.

 Is there a method to move the pointer of file to beginning of 
 file or to any position (for example back to 2nd row), without 
 to close the file?

 Thank you very much.
 Regards
 Giovanni
Use File (https://dlang.org/library/std/stdio/file.html) And seek() (https://dlang.org/library/std/stdio/file.seek.html) And then one of its read functions. rawRead will let you read the raw bytes at the position.
Jan 18 2019
parent Giovanni Di Maria <calimero22 yahoo.it> writes:
On Friday, 18 January 2019 at 08:49:08 UTC, bauss wrote:
 On Friday, 18 January 2019 at 08:10:25 UTC, Giovanni Di Maria 
 wrote:
 Hi All
 I have a text file like this:

 111111
 222222
 333333
 444444
 555555
 666666
 777777
 ......

 I execute these functions:

 i = archive.readln();
 i = archive.readln();
 i = archive.readln();
 i = archive.readln();

 so "i" is 444444.

 Is there a method to move the pointer of file to beginning of 
 file or to any position (for example back to 2nd row), without 
 to close the file?

 Thank you very much.
 Regards
 Giovanni
Use File (https://dlang.org/library/std/stdio/file.html) And seek() (https://dlang.org/library/std/stdio/file.seek.html) And then one of its read functions. rawRead will let you read the raw bytes at the position.
Thank you very very much. Giovanni
Jan 18 2019