Program crashes after trying to use a recently created file. C#

Posted by Jason T. on Stack Overflow See other posts from Stack Overflow or by Jason T.
Published on 2010-05-26T15:04:39Z Indexed on 2010/05/26 15:11 UTC
Read the original article Hit count: 205

Filed under:
|
|

So here is my code

if (!File.Exists(pathName))
{
    File.Create(pathName);
}
StreamWriter outputFile = new StreamWriter(pathName,true);

But whenever I run the program the first time the path with file gets created. However once I get to the StreamWriter line my program crashes because it says my fie is in use by another process. Is there something I'm missing between the File.Create and the StreamWriter statements?

© Stack Overflow or respective owner

Related posts about c#

Related posts about file-io