I'm trying to read in a 150mb text file into a Rich Text box.
Currently, I am using a StreamReader to iterate through each line in the file, appending every line to a StringBuilder instance.
This works for smaller files, but I get a System.OutOfMemory exception when trying to read large files.
I don't see any problems with reading a 150mb file - there is plenty of physical memory and that's well within the Windows 32-bit application address space.
If anyone here has any idea how to do this, It would be greatly appreciated.
I'll attach my code at the end.
Thanks.
StringBuilder sb = new StringBuilder();
using (StreamReader sr = new StreamReader(fileLocation))
{
string line;
while ((line = sr.ReadLine()) != null)
{
sb.AppendLine(line);
}
}
return sb;
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…