I have created a streamReader, but the first ‘ReadLine()’ reads the 14th line in the file, not the first, and I don’t know why this is.
My code is:
StreamReader reader = new StreamReader("argus-BIG.txt");
//create array to hold data values
string[] branchData = new string[11];
//get 11 lines of branch data file and store in an array
for (int i = 0; i < 11; i++)
{
branchData[i] = reader.ReadLine();
}
//new instance of Branch Class
Branch tempBranch = new Branch();
//set branch values from branchData array
tempBranch.setBranchID(branchData[0]);
tempBranch.setBranchNickname(branchData[1]);
tempBranch.setBranchAddressNo(branchData[2]);
tempBranch.setBranchAddressStreet(branchData[3]);
tempBranch.setBranchAddressCity(branchData[4]);
tempBranch.setBranchAddressCountry(branchData[5]);
tempBranch.setBranchAddressPostCode(branchData[6]);
tempBranch.setNearestBranch1(branchData[7]);
tempBranch.setNearestBranch2(branchData[8]);
tempBranch.setNearestBranch3(branchData[9]);
tempBranch.setNoCategories(Convert.ToInt32(branchData[10]));
I wrote a test app, which worked, then copied and pasted the code (which looked identical to me) back into my main program, and it worked. Thanks for your help
This should be working, and I am guessing that there is something else happening along the way. Once you open a reader, it moves down and must be reset if you want it back to reading from the top. Maybe your reference was left open elsewhere (but that is assuming that the posted code has something happening that was not posted), or used before this piece of code?
However, you can always force the position to the top to verify this theory. If after this code, you still are at the 14th line, then it might be the file itself somehow?