あるテキスト(CSVファイル)を1行ずつ読込み、条件にあう行のみ別ファイルに書き込み処理
を作成したのですが読み込むファイルのサイズが4GB程度あり(書き込み後の想定は1GB程度)、
処理中にSystem.OutOfMemoryExceptionが発生します。
読み込みの方法等、何か良い対策はないでしょうか?
開発:VB.NET
Try
Dim srFile As New System.IO.StreamReader("読込みファイル.csv", System.Text.Encoding.Default)
Dim sw As New System.IO.StreamWriter("書込みファイル.csv", False, System.Text.Encoding.GetEncoding(932))
'1行ずつ最後まで読み込む
Dim strLine As String = "#"
While Not strLine Is Nothing
'1行ずつ読み込む
strLine = srFile.ReadLine()
If strLine = Nothing Then
'何も読み込まない時はWhile分を抜ける
'Exit While
Else
Dim str1() As String = strLine.Split(",")
If 条件(str1 = "1") Then
'書込み処理
sw.Write(strLine)
sw.Write(vbCr + vbLf)
End If
End If
End While
srFile.Close()
sw.Close()
Return true
Catch ex As Exception
Return false
End Try
質問者:Dra