以下代码给我该错误“ System.IO.IOException:'该进程无法访问文件'C:\Users\user1\Desktop\exampleText.txt' because it is being used by another process"
这是代码:
Regex regex = new Regex(regexBox.Text, RegexOptions.Singleline);
foreach(string file in fileNames)
{
var currentFile = File.Open(file, FileMode.Open, FileAccess.Read);
string[] texts = File.ReadAllLines(currentFile.Name);
currentFile.Close();
var match = regex.Matches(texts.ToString())
.Cast<Match>()
.Select(m => m.Value)
.ToArray(); ;
textBox1.Lines = match;
Array.Copy(match, myTexts,match.Length);
}
知道为什么我会收到该错误吗?