Не записывает текст в файл=( Подскажите, пожалуйста, что не так?
string CurrentDirectory = Directory.GetCurrentDirectory();
if (!System.IO.File.Exists(CurrentDirectory + @"\update.txt"))
{
File.Create(CurrentDirectory + @"\update.txt");
using (FileStream fstream = new FileStream(CurrentDirectory + @"\update.txt", FileMode.OpenOrCreate))
{
string text = "hello!";
byte[] array = System.Text.Encoding.Default.GetBytes(text);
fstream.Write(array, 0, array.Length);
}
}
Где-то здесь using (FileStream fstream = new FileStream(CurrentDirectory + @"\update.txt", FileMode.OpenOrCreate)) вылетает исключение о том, что файл занят другим процессом?
Это потому что здесь File.Create(CurrentDirectory + @"\update.txt"); создаётся новый файл и без освобождения ресурсов следом к нему осуществляется новое обращение new FileStream(CurrentDirectory + @"\update.txt", FileMode.OpenOrCreate).
File.Create(Файл).Dispose() или же так using (File.Create(Файл)) { }.File.Create(CurrentDirectory + @"\update.txt") нет необходимости, т.к. FileStream с параметром FileMode.OpenOrCreate в любом случае создаст файл на следующем шаге.Основные этапы разработки сайта для стоматологической клиники
Продвижение своими сайтами как стратегия роста и независимости