Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/292.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在c中写入文本文件时发生IoException#_C#_Regex_Text Files_File Handling - Fatal编程技术网

C# 在c中写入文本文件时发生IoException#

C# 在c中写入文本文件时发生IoException#,c#,regex,text-files,file-handling,C#,Regex,Text Files,File Handling,我有一个文本文件,我需要根据正则表达式匹配更新它,但是当我的程序试图在文本文件中写入一行时,它给出了以下错误 The process cannot access the file 'D:\Archieve\20140123.text' because it is being used by another process. 这是我的密码 哪里出错了?使用File.Create(textfilename.Close() 正如错误消息所示,创建文件不需要单独的指令。 StreamWriter将处理

我有一个文本文件,我需要根据正则表达式匹配更新它,但是当我的程序试图在文本文件中写入一行时,它给出了以下错误

The process cannot access the file 'D:\Archieve\20140123.text' because it is being used by another process.
这是我的密码

哪里出错了?

使用
File.Create(textfilename.Close()


正如错误消息所示,创建文件不需要单独的指令。 StreamWriter将处理它:下面是您所使用的构造函数的描述

> Initializes a new instance of the StreamWriter class for the specified
> file by using the default encoding and buffer size. If the file
> exists, it can be either overwritten or appended to. If the file does
> not exist, this constructor creates a new file.
TextWriter tsw = new StreamWriter(textfilename,true);
> Initializes a new instance of the StreamWriter class for the specified
> file by using the default encoding and buffer size. If the file
> exists, it can be either overwritten or appended to. If the file does
> not exist, this constructor creates a new file.