Dim FileMemCnt As Integer = File.ReadAllBytes(filePath).Length
大家好,
我试图找出一种方法来确定CSV文件中1000行的字节大小,可能有10-20K行。一旦我得到了字节大小的块,我就可以将文件拆分成每1000行的较小文件。 有没有人知道一种方法可以让我因此得到我需要的确切字节大小块?
下面是我用chunksize变量中的字节来切断csv文件的代码:
Function ChopItUp(ByVal inputFile As String, ByVal chunkSize As Integer) As Integer '1000000 = 1MB (1x6) chunkSize in bytes
Dim reader As New FileStream(inputFile, FileMode.Open)
Dim fileIndex As Integer = 1
Dim buffer(chunkSize) As Byte
Dim writer As FileStream
Dim bytesRead As Integer
inputFile = Replace(inputFile, ".csv", "P")
Do
bytesRead = reader.Read(buffer, 0, chunkSize)
If bytesRead > 0 Then
writer = New FileStream(inputFile & fileIndex & ".csv", FileMode.Create)
writer.Write(buffer, 0, bytesRead)
writer.Close()
fileIndex = fileIndex + 1
End If
Loop While bytesRead > 0
reader.Close()
ChopItUp = fileIndex - 1
End Function
.
上面我发布了一小段代码我可以读取每个文件的完整字节大小,那么有没有类似于读取每1000条记录的字节数的方法?