Index out of bounds array exception +Streamreader
I have encountered an array index out of bounds exception based on t开发者_StackOverflow社区he following codes:
I understand that readtoend method may disrupt the pointer for the streamreader, hence i implement the discardbuffereddata and seekorigin 0. However, im still getting an index out of bounds. help please? thanks!
StreamReader sr = new StreamReader(@".\Input\" + inServer + ".txt");
readall = sr.ReadToEnd();
string[] splited = Regex.Split(readall, "~~~~~~~~~~~~~~");
sr.BaseStream.Seek(0, SeekOrigin.Begin);
sr.DiscardBufferedData();
while (sr.Peek() >= 0)
{
currLine = sr.ReadLine();
}
try modifying your codes as follows:
readAll = sr.ReadToEnd();
sr.Close();
foreach (string s in readAll.Split(new char[] { '\r', 'n' }))
{
currLine = s;
精彩评论