www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Reading a file using stream.

reply Carlos Madureira <Carlos_member pathlink.com> writes:
I was looking at the code in samples/d2html.d and it doesn't use it but waits
for a exception to get out of the while loop. 

I want to read a file in chunks, but the exception doesn't seem like a good
mechanism to exit the while loop and the implementation of eof() for files seems
slow since it uses seeking.

InputStream is = File("test.txt");
while (is.eof())
{
is.read(buffer);
..
}
Jan 18 2006
parent reply "Ben Hinkle" <bhinkle mathworks.com> writes:
"Carlos Madureira" <Carlos_member pathlink.com> wrote in message 
news:dqm5gc$193c$1 digitaldaemon.com...
I was looking at the code in samples/d2html.d and it doesn't use it but 
waits
 for a exception to get out of the while loop.

 I want to read a file in chunks, but the exception doesn't seem like a 
 good
 mechanism to exit the while loop and the implementation of eof() for files 
 seems
 slow since it uses seeking.

 InputStream is = File("test.txt");
 while (is.eof())
 {
 is.read(buffer);
 ..
 }
use a std.stream.BufferedFile or a std.cstream.CFile (which is buffered by the C runtime). Unbuffered file i/o will be slow. Also not I think you want while (!is.eof()).
Jan 18 2006
parent reply Hasan Aljudy <hasan.aljudy gmail.com> writes:
Ben Hinkle wrote:
 "Carlos Madureira" <Carlos_member pathlink.com> wrote in message 
 news:dqm5gc$193c$1 digitaldaemon.com...
 
I was looking at the code in samples/d2html.d and it doesn't use it but 
waits
for a exception to get out of the while loop.

I want to read a file in chunks, but the exception doesn't seem like a 
good
mechanism to exit the while loop and the implementation of eof() for files 
seems
slow since it uses seeking.

InputStream is = File("test.txt");
while (is.eof())
{
is.read(buffer);
..
}
use a std.stream.BufferedFile or a std.cstream.CFile (which is buffered by the C runtime). Unbuffered file i/o will be slow. Also not I think you want while (!is.eof()).
"is" is a keyword! Cannot be used as an identifier.
Jan 19 2006
parent "Ben Hinkle" <ben.hinkle gmail.com> writes:
"Hasan Aljudy" <hasan.aljudy gmail.com> wrote in message 
news:dqpmaa$1896$1 digitaldaemon.com...
 Ben Hinkle wrote:
 "Carlos Madureira" <Carlos_member pathlink.com> wrote in message 
 news:dqm5gc$193c$1 digitaldaemon.com...

I was looking at the code in samples/d2html.d and it doesn't use it but 
waits
for a exception to get out of the while loop.

I want to read a file in chunks, but the exception doesn't seem like a 
good
mechanism to exit the while loop and the implementation of eof() for 
files seems
slow since it uses seeking.

InputStream is = File("test.txt");
while (is.eof())
{
is.read(buffer);
..
}
use a std.stream.BufferedFile or a std.cstream.CFile (which is buffered by the C runtime). Unbuffered file i/o will be slow. Also not I think you want while (!is.eof()).
"is" is a keyword! Cannot be used as an identifier.
hehe. good point. I totally missed that one. Plus I spelled "note" as "not". :-P
Jan 19 2006