I did:
if (averagesListTextFile != null)
{
Directory.CreateDirectory(subDirectoryName);
File.Create(subDirectoryName + "\\" + averagesListTextFile + ".txt");
And then I want to do:
reader = new StreamReader(subDirectoryName + "\\" + averagesListTextFile + ".txt");
But I’m getting error say the file is in use by another process…And that happen only after I did the File.Create
File.Createreturns a stream, so you need to dispose it:or equivalently in this case:
But if you’ve just created the file, why would you try to read it? It will be empty.
Note that your reader should use a
usingstatement too. Alternatively, to read and write complete text files, you should look intoFile.WriteAllTextandFile.ReadAllText, which make life simpler.