solutionsdxb
Member
- Joined
- Mar 18, 2009
- Messages
- 8
- Programming Experience
- 1-3
Hi,
i want to split a text file in two part , as the file size is approx 30 GB , how can i achieve this is vb.net , i am having a ram of about 4 GB.
I got one solutions of split the file but its split into various text file i just want it to split in two part the first part should contain first 9 lines and the second part contains the rest of the lines.
kindly suggest any modification can be done with the current code to achieve the same.
i want to split a text file in two part , as the file size is approx 30 GB , how can i achieve this is vb.net , i am having a ram of about 4 GB.
I got one solutions of split the file but its split into various text file i just want it to split in two part the first part should contain first 9 lines and the second part contains the rest of the lines.
kindly suggest any modification can be done with the current code to achieve the same.
VB.NET:
Sub TextSplitter()
Dim fsIN, fsOut As IO.FileStream
Dim sr As IO.StreamReader
Dim sw As IO.StreamWriter
Dim OutCount As Integer
fsIN = New IO.FileStream( _
"infile.txt", IO.FileMode.Open, IO.FileAccess.Read _
)
sr = New IO.StreamReader(fsIN, System.Text.Encoding.Default)
Do
Dim Line As String
Dim LineCount As Integer
Line = sr.ReadLine()
If Line Is Nothing Then Exit Do
If fsOut Is Nothing Then
OutCount += 1
fsOut = New IO.FileStream( _
"outfile" & OutCount & ".txt", _
IO.FileMode.CreateNew, IO.FileAccess.Write _
)
sw = New IO.StreamWriter(fsOut, System.Text.Encoding.Default)
LineCount = 0
End If
sw.WriteLine(Line)
LineCount += 1
If LineCount = 20000 Then
sw.Close()
fsOut = Nothing
End If
Loop
If fsOut IsNot Nothing Then
sw.Close()
End If
fsIN.Close()
End Sub