Answer the question
In order to leave comments, you need to log in
How to work with files in C#?
Well, let's say...
I ask the user what file he wants to create and where. -The user enters the path to the file (including the file itself).
I create this file using File.Create()...
AND HERE IS THE BIG PROBLEM!
When I try to write to a file, they write to me that this file is being occupied by another process (as I understand it, by an I / O stream due to the fact that I used File.Create() )
Okay. Let's say you can even do WITHOUT File.Create() (just found out that File.WriteAllText() creates a file along with writing)...
But sorry. And how to delete an input/output stream? This file will hang in the PC memory without the ability to close it or what? For the method Close () I did not find something.
Answer the question
In order to leave comments, you need to log in
Use using when working with files.
using(var file = File.Create(path)) {
// делаем все нужные дела через объект file
} // а тут файл автоматически закроется
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question