Error The process cannot access the file because This file is being used by another process. What I need is to develop a class file, to provide the ability to add to its end. Actually it is a code with Form.
if (match.Success) ; else throw new IOException(" Неверный формат имени файла."); File file1 = new File(file_Name, text); file1.Add(file_Name, text); file1.get_Info(textBox1); ... catch (Exception ex)// тут ошибка, если обработку оставить Now the File class
public File (string f_Name, string info) if (f_Name != null && info != null) if (System.IO.File.Exists(f_Name)) FileInfo exist_File = new FileInfo(f_Name); //Заполняем поля else System.IO.File.Create(f_Name); FileInfo create_File = new FileInfo(f_Name); //Заполняем поля Here, that above I have some problems with the logic of the program, at the same time you can tell.
public void Add(string f_name,string new_text) { ошибка тут, если без try ... catch using (StreamWriter f_Stream = new StreamWriter(f_name, true, System.Text.Encoding.Default)) { byte[] array = System.Text.Encoding.Default.GetBytes(new_text); //int temp_Length = Convert.ToInt32(Length); //Length += array.Length; f_Stream.Write(new_text); Information += Environment.NewLine + new_text; What is wrong: 1) If a file with the same name is not created, an error occurs (see the header), but the file is created, adding to it is possible (from another button). 2) If the file already exists, then everything is fine, we add a line to the end of the file and output information on it.
What cant?
System.IO.File.Createcreates a file and returns a file stream —FileStream— until it is closed, there is no more access. - Alexander Petrov