Thread overview | ||||||
---|---|---|---|---|---|---|
|
January 18, 2006 Reading a file using stream. | ||||
---|---|---|---|---|
| ||||
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); .. } |
January 18, 2006 Re: Reading a file using stream. | ||||
---|---|---|---|---|
| ||||
Posted in reply to Carlos Madureira | "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()). |
January 20, 2006 Re: Reading a file using stream. | ||||
---|---|---|---|---|
| ||||
Posted in reply to Ben Hinkle | 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.
|
January 20, 2006 Re: Reading a file using stream. | ||||
---|---|---|---|---|
| ||||
Posted in reply to Hasan Aljudy | "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 |
Copyright © 1999-2021 by the D Language Foundation