|
-
Nov 11th, 2005, 10:47 AM
#1
Thread Starter
Frenzied Member
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 ?
-
Nov 11th, 2005, 10:50 AM
#2
Re: Read entire content of file
Try penagate's code in Post #3 of this thread and see what you think.
-
Nov 11th, 2005, 10:58 AM
#3
Thread Starter
Frenzied Member
Re: Read entire content of file
 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
-
Nov 11th, 2005, 10:59 AM
#4
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
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
-
Nov 11th, 2005, 11:01 AM
#5
Re: Read entire content of file
 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.
-
Nov 11th, 2005, 11:04 AM
#6
Thread Starter
Frenzied Member
Re: Read entire content of file
 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
??
-
Nov 11th, 2005, 11:08 AM
#7
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)
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
-
Nov 11th, 2005, 11:26 AM
#8
Thread Starter
Frenzied Member
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
Last edited by sebs; Nov 11th, 2005 at 11:34 AM.
-
Nov 11th, 2005, 12:23 PM
#9
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|