c# - FileNotFoundException occurs only when running outside the debugger -
i have simple code opens txt file:
streamreader sourcefile = file.opentext(filename)
the thing is, when press ctrl-f5 start program, file doesn't exist error. when press f11 go step step, runs smooth , no errors or ever happens , desired results. idea cause of this?
i'm using visual studio c# express 2010.
the code in program.cs:
class1.readpointsfile(@"points.txt");
the function:
public void readpointsfile(string filename) { if (!file.exists(filename)) { console.writeline("file doesn't exist."); return; } using (streamreader sourcefile = file.opentext(filename)) { string inputline; int arraysize; arraysize = convert.toint32(sourcefile.readline()); pointsarray = new point2d[arraysize]; int i_keeptrack = 0; inputline = sourcefile.readline(); { string[] coordinations = inputline.split(' '); pointsarray[i_keeptrack] = new point2d(double.parse(coordinations[0]), double.parse(coordinations[1])); i_keeptrack++; inputline = sourcefile.readline(); } while (inputline != null); } }
that's problem of running path: debugging, start program on bin\debug folder (where file present), meanwhile using ctrl+f5 run without debug, program starts on bin\release folder.
Comments
Post a Comment