C# exception. File is being used by another process

前端 未结 7 1762
北恋
北恋 2020-12-19 06:43

I\'m playing around with C# and I encountered a problem. When I try to make a new file, the program breaks and says that the file is being used by another process. It\'s pro

7条回答
  •  没有蜡笔的小新
    2020-12-19 06:53

    Your problem seems to be in SaveBtn_Click event, you are using your destination file twice for writing:

    File.Create(NameTb.Text + ".txt");
    TextWriter tw = new StreamWriter(NameTb.Text + ".txt"); 
    

    Remove this line:

    File.Create(NameTb.Text + ".txt");
    

提交回复
热议问题