Read entire content of file
What is the fastest way to read an entire file !
I did some test and FSO is faster when I use TextStreamObject.ReadAll then using the old Open and looping with Input, which was way slower.
But I looks like the .ReadAll is limited is size, could that be ?
Re: Read entire content of file
Try penagate's code in Post #3 of this thread and see what you think.
Re: Read entire content of file
Quote:
Originally Posted by Hack
Try penagate's code in Post #3 of
this thread and see what you think.
Awesome, thanks Hack,
Didn't know you could do it in one statement.
Plus I don't need FSO anymore, wooo hooo !
One small questions, I always use Integer for the freefile, penagate uses a Long, I guess it should be that way ?
And does the () make a difference ?
Thanks a lot
Re: Read entire content of file
or use Binary .. its faster than Input:
VB Code:
Open "C:\path\to\file.txt" For Binary As #1
tmp = Space(LOF(1))
Get #1, , tmp
Close #1
Re: Read entire content of file
Quote:
Originally Posted by sebs
One small questions, I always use Integer for the freefile, penagate uses a Long, I guess it should be that way ?
I really don't think it makes much of a difference. penagate, like myself, uses long pretty much out of habit even though in many cases integer would work just fine.
Re: Read entire content of file
Quote:
Originally Posted by Static
or use Binary .. its faster than Input:
VB Code:
Open "C:\path\to\file.txt" For Binary As #1
tmp = Space(LOF(1))
Get #1, , tmp
Close #1
You mean Get instead of Input ?
So
VB Code:
Open "C:\path\to\file.txt" For Binary As #1
tmp = Space(LOF(1))
Get #1, , tmp
Close #1
is faster than
VB Code:
Open "C:\path\to\file.txt" For Binary Access Read Lock Write As #1
tmp = Input(1, LOF(1))
Close #1
??
Re: Read entire content of file
from what I have tested before...
trying to open a 110MB file.. it was significantly faster....
well, wait... I was using
Open "C:\path\to\file.txt" For Input As #1
for the test...
never tried it with :
Open "C:\path\to\file.txt" For Binary Access Read Lock Write As #1
(And that seems like overkill!!! lol)
Re: Read entire content of file
Hmm, I have a Overflow error with penagate's code and not Static's code, weird.
I'll use Static then :)
Thanks
Re: Read entire content of file
I used the high-resolution performance timer to test the speeds of these methods.
The Get method is much faster
VB Code:
Open "C:\path\to\file.txt" For Binary Access Read As #1
tmp = Space(LOF(1))
Get #1, , tmp
Close #1
BTW you have an error in the Input method, should be
VB Code:
Open "C:\path\to\file.txt" For Binary Access Read As #1
tmp = Input(LOF(1), #1)
Close #1