本文介绍了如何在VB.NET中读取大文本文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨..我正在研究一个读取文本文件的项目。我使用READBLOCK打开文件。打开大文件时出错。打开10MB文件时没有问题,但打开1GB文件时出错。



这是打开/读取文件的代码部分:

Hi .. I''m working on a project that reads a text file. I open the file using READBLOCK. I get an error when opening big files. No issues when opening a 10MB file but got an error when opening a 1GB file.

Here''s the part of the code that opens/reads the file:

Const MAX_BYTES As Integer = 1048576 * 5 '=10 MB 
Dim bytesRead(MAX_BYTES) As Char
Dim numBytesRead As Integer
Dim currentPos As Integer = 0
Dim strFileName As String
Dim strm As System.IO.Stream
Dim TextLine As String
Dim FileDetail As IO.FileInfo

OpenFileDialogMain.ShowDialog()
strm = OpenFileDialogMain.OpenFile()
strFileName = OpenFileDialogMain.FileName.ToString()

Using reader As System.IO.TextReader = System.IO.File.OpenText(strFileName)
  numBytesRead = reader.ReadBlock(bytesRead, currentPos, MAX_BYTES)
  TextLine = reader.ReadLine()
End Using

txtEditor.Text = New String(bytesRead)
txtEditor.Text += TextLine
txtEditor.Text = txtEditor.Text & vbCrLf & Now



有没有人对如何打开大文件有任何建议?



谢谢!


Does anyone have any suggestion on how to open a large file?

Thanks!

推荐答案

im file As New FileInfo("path\to\file")

Using reader As StreamReader = file.OpenText()
    While Not reader.EndOfStream
        Dim nextLine As String = reader.ReadLine()
        ProcessLine(nextLine)
    End While
End Using





大读取的挑战在 []



这篇关于如何在VB.NET中读取大文本文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-05 06:34