Click here to Skip to main content
15,895,799 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
How do I read a text file (into a textbox of course) which is 1.5 gb in vb.net?
I would have to read it char by char wouldn't I?
Posted
Comments
PIEBALDconsult 14-Mar-15 18:30pm    
That is not a reasonable thing to do. What are you _actually_ trying to accomplish?
iProgramIt 14-Mar-15 18:40pm    
I want to open a text file (which stores pi digits 0 - 1,500,000,000) into a textbox without crashing my app
[no name] 14-Mar-15 18:41pm    
What is it good for to have it all at once in a textbox?
PIEBALDconsult 14-Mar-15 18:41pm    
Pointless.
iProgramIt 14-Mar-15 18:45pm    
I JUST WANT AN ANSWER!
A day goes by, and everyone just gets ruder...

No matter what you do, putting 1.5GB worth of text into a TextBox will take forever. It takes about 1 minute just to do 10MB.

There's simply no way around it and definitely no reason to do it. What user is going to want to view all of that data? None.

Now, WHY are you trying to cram that much data into a TextBox? There may be other ways to do what you're trying to do.
 
Share this answer
 
Comments
CPallini 15-Mar-15 7:42am    
My 5.
 
Share this answer
 
Note that CLR objects have max size limit of 2GB and if you cross it you get OutOfMemoryException.
String objects consume approximately the following:
20 bytes for the object + 2 bytes per character for the object's inner buffer

So you would need (note that I presume your PI text file is ASCII encoded):
20 + 2 * 1.5GB

However nowadays there is actually a way to make such a big string, in .NET 4.5 a gcAllowVeryLargeObjects feature was introduced.
But nevertheless by passing the default limit you just know that it will not run smoothly at all, the users experience will be terrible.

So as an alternative how about you paginate its content, in other words how about you display just a part of its content, let's say 10k chars, and allow user to move 10kB back and 10kB forward.
For example something like this:
VB
' The PI text file.
Dim piFile As String = "C:\PI.txt"
' The character size for a part of PI text.
Dim piTextPartSize As Integer = 10000
' Part of PI text.
Dim piTextPart As String

' The indexer that indicates which part to read.
' You could increment and decrement its value with 'Next' and 'Back' buttons.
Dim piPartIndex As Integer = 0

' ...

' Here is how to read a specific PI text file's part.
Using piReader = New StreamReader(piFile)
	Dim piPartCharacters As Char() = New Char(piTextPartSize - 1) {}

	piReader.BaseStream.Position = piPartIndex * piTextPartSize
	piReader.Read(piPartCharacters, 0, piTextPartSize)

	piTextPart = New String(piPartCharacters)
End Using
 
Share this answer
 
v4

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900