need help: stream reader says its at the end of stream but there are still more lines i want it to r

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
i am trying to read data from a text file into an array but it only reads the first line and then says its at the end of stream. the code is as follows:
<pre class="prettyprint private void button2_Click(object sender, EventArgs e)
{
// open EQE data text file and put it into an array
Stream myStream2 = null;
OpenFileDialog openFileDialog2 = new OpenFileDialog();
openFileDialog2.InitialDirectory = "Desktop";
openFileDialog2.Filter = "all files (*.*)|*.*|text files (*.txt)|*.txt;*.titx";
openFileDialog2.FilterIndex = 2;
openFileDialog2.RestoreDirectory = true;
openFileDialog2.Multiselect = false;
if (openFileDialog2.ShowDialog() == DialogResult.OK)
{
try
{
if ((myStream2 = openFileDialog2.OpenFile()) != null)
{
using (myStream2)
{
try
{
using (StreamReader sr2 = new StreamReader(openFileDialog2.FileName))
{
int count = 0;
sr2.ReadLine();
while (!sr2.EndOfStream)
{
string EQED = sr2.ReadLine();
string[] midEQEData = EQED.Split(;);
int i;
int loc = 1;
for (i = count; i < (midEQEData.GetLength(0))+count; i++)
{
if (loc == 1)
{
EQEData[(i / 4), 0] = Convert.ToDouble(midEQEData);
loc = 2;
}
else if (loc == 2)
{
EQEData[(i / 4), 1] = Convert.ToDouble(midEQEData);
loc = 3;
}
else if (loc == 3)
{
EQEData[(i / 4), 2] = Convert.ToDouble(midEQEData);
loc = 4;
}
else if (loc == 4)
{
EQEData[(i / 4), 3] = Convert.ToDouble(midEQEData);
loc = 1;
}
count = count + 5;
}
}
}
}
catch (Exception err)
{
// Lets the user know if something went wrong.
Console.WriteLine("The file could not be read:");
Console.WriteLine(err.Message);
}
}
}
}
catch (Exception ex)
{
MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message);
}
}
textBox2.Text = openFileDialog2.FileName;
}[/code]
how do i fix this? any help is really appreciated


View the full article
 
Back
Top