I have this code, the idea is to read from a file and the delete the file.
StreamReader sr = new StreamReader(path);
s = sr.ReadLine();
if ((s != null))
{
sr.ReadLine();
do
{
// I start to read and get the characters
}while (!(sr.EndOfStream));
}
sr.close();
and then after close the streamReader,
I try to delete the file but I can’t:
“The process cannot access the file because it is being used by another process”
What can I do?
Try deleting after enclosing your code in a
usingstatement as follows:If that does not work either, then some other process has locked your file.