On Sep 22, 2:02 am, "Jerry Spence1" <1...@dfgh.comwrote:
I'm doing:
Dim Contents() As String = System.IO.File.ReadAllLines("C:\MyFile.txt") with
upwards of 100,000 lines.
This is a brilliantly simple and fast way of creating an array from a text
file. However, it seems to be restricted as there are no overloads for
FileSharing (I have another application which might add to the file whilst
it is being read). The only alternative I have found is using a large amount
of looping with StreamReader which takes forever.
Is there another way?
-Jerry
I'm not sure why you think a StreamReader would any slower than
calling ReadAllLines. Here is the code for the ReadAllLines method:
Public Shared Function ReadAllLines(ByVal path As String, ByVal
encoding As Encoding) As String()
Dim list As New ArrayList
Using reader As StreamReader = New StreamReader(path, encoding)
Dim str As String
Do While (Not str = reader.ReadLine Is Nothing)
list.Add(str)
Loop
End Using
Return DirectCast(list.ToArray(GetType(String)), String())
End Function
As you can see, it is using a StreamReader.
Chris