Vb.net 长度超过2GB的字符串
我需要将几个文本文件连接在一起,每个输入文件大约为3.5GB。这些是在行尾包含vbCrLf的简单文件 我以前用于从网页获取文本流的一些代码(见下文)使用了Peek函数(见下文),我想知道Peek是否可以用于从文件中读取小于2GB的数据-->写入连接的文件,然后继续处理每个文件的后半部分Vb.net 长度超过2GB的字符串,vb.net,string,out-of-memory,Vb.net,String,Out Of Memory,我需要将几个文本文件连接在一起,每个输入文件大约为3.5GB。这些是在行尾包含vbCrLf的简单文件 我以前用于从网页获取文本流的一些代码(见下文)使用了Peek函数(见下文),我想知道Peek是否可以用于从文件中读取小于2GB的数据-->写入连接的文件,然后继续处理每个文件的后半部分 Dim encode As Encoding = System.Text.Encoding.GetEncoding("utf-8") Dim readStream As New StreamReader(re
Dim encode As Encoding = System.Text.Encoding.GetEncoding("utf-8")
Dim readStream As New StreamReader(recvStream, encode)
Dim sPage As String
sPage = ""
While (readStream.Peek() > -1)
sPage += readStream.ReadLine() + vbCrLf
End While
基本上,我不能使用Peek、write(concatenate)、Peek、concatenate等来读取高达(比如)1.8GB的数据,而不会丢失任何数据。是否还有其他需要3.5GB流才能使用StreamWriter编写的内容 解决方案如下:
Dim encode As Encoding = System.Text.Encoding.GetEncoding("utf-8")
Dim readStream As New StreamReader(recvStream, encode)
Dim str, sPage As String
sPage = ""
While (readStream.Peek() > -1)
sPage += readStream.Read(str, 0, 32768)
End While
'Next, split the string into lines at the carriage returns
Dim Buff() As String = Split(sPage, vbCrLf)
解决方案如下:
Dim encode As Encoding = System.Text.Encoding.GetEncoding("utf-8")
Dim readStream As New StreamReader(recvStream, encode)
Dim str, sPage As String
sPage = ""
While (readStream.Peek() > -1)
sPage += readStream.Read(str, 0, 32768)
End While
'Next, split the string into lines at the carriage returns
Dim Buff() As String = Split(sPage, vbCrLf)
该应用程序是64位版本Windows上的64位应用程序吗?您是否看到过允许分块读取的重载?然后,在读取每个块时,只需将数据写入目标文件,而不是将数据存储在字符串中。我建议从32768开始设置缓冲区大小。谢谢@Andrew-StreamReader。Read成功解决了问题。@LEP如果您找到了解决方案,请将其作为答案发布并接受,这样将来的读者可能会发现它很有用。VB.net和VBA是不同的语言。代码和问题是面向VB.net的,但问题的标题和标记是VBA。这有点令人困惑。如果不是VBA,则应将其编辑掉。该应用程序是64位版本Windows上的64位应用程序吗?您是否看到过允许您成批读取的重载?然后,在读取每个块时,只需将数据写入目标文件,而不是将数据存储在字符串中。我建议从32768开始设置缓冲区大小。谢谢@Andrew-StreamReader。Read成功解决了问题。@LEP如果您找到了解决方案,请将其作为答案发布并接受,这样将来的读者可能会发现它很有用。VB.net和VBA是不同的语言。代码和问题是面向VB.net的,但问题的标题和标记是VBA。这有点令人困惑。如果不是VBA,则应将其编辑掉。