Home > Enterprise >  OpenTextFile vs Open file
OpenTextFile vs Open file

Time:05-10

I've been using the Open method when dealing with files. I just found out about OpenTextFile and CreateTextFile. What is the difference between them and the Open method? Is one faster then the other? Or which is better?

Dim fs, f
Set fs = CreateObject("Scripting.FileSystemObject")
Set f = fs.OpenTextFile("c:\testfile.txt", 1, TristateFalse)
f.Close
Dim line as String
Open "c:\testfile.txt" For Input as #1
Line Input #1, line
Close #1

CodePudding user response:

Overall, Open is faster. However, it can only read files up to ~2gb and cannot read Linux EOL indicators. OpenTextFile on the other hand, creates a textstream that can read bigger files and read Linux EOL indicators, but, is approximatly 4 times slower than Open.

  • Related