Ce qui suit lève une exception " The process cannot access the file 'D:\MyDir\First.txt' because it is being used by another process.
"
static void Main(string[] args)
{
Directory.CreateDirectory(@"D:\MyDir");
File.Create(@"D:\MyDir\First.txt");
File.WriteAllText(@"D:\MyDir\First.txt", "StackOverflow.com");
}
Cependant les travaux suivants:
using (File.Create(@"D:\MyDir\First.txt"))
{
}
ou
File.Create(@"D:\MyDir\First.txt").Close();
Pourquoi? Que doit-on fermer en File.Create
?