I have a code which reads text from 10 files each of the size of approximately 80MB. However, I am unable to do this successfully as (depending on the way I tried) it fails on 3rd-7th iteration. The commented-out lines are the ways that I tried reading it, each of them fails.
var lines = new List<string>();
var text = string.Empty;
for (int i = 0; i < 10; i++)
{
try
{
//lines.AddRange(File.ReadAllLines(dirPath + string.Format(@"commands{0}.txt", i)));
//lines.Add(File.ReadAllText(dirPath + string.Format(@"commands{0}.txt", i)));
//lines.Add(text);
var bytes = File.ReadAllBytes(dirPath + string.Format(@"commands{0}.txt", i));
text += Environment.NewLine + System.Text.Encoding.UTF8.GetString(bytes);
}
catch (Exception e)
{
//OutOfMemory exception
}
}
What am I doing wrong? What exactly gets capped? MB allowed for application, length of a string, count of items in a list? Etc.?