【发布时间】:2012-01-29 03:01:57
【问题描述】:
我有这段代码,想法是从文件中读取并删除文件。
StreamReader sr = new StreamReader(path);
s = sr.ReadLine();
if ((s != null))
{
sr.ReadLine();
do
{
// I start to read and get the characters
}while (!(sr.EndOfStream));
}
sr.close();
然后在关闭streamReader之后, 我尝试删除该文件,但我不能:
“该进程无法访问该文件,因为它正被另一个进程使用”
我能做什么?
【问题讨论】:
-
是excel文件还是其他文件?
-
代码(片段)看起来过于复杂,从你描述的目标来看有点脆弱。显示完整的代码/功能,至少到您尝试删除文件的部分。
-
这是一个txt代码,我用sr.Dispose()试了一下,还是不行
-
你能说出路径变量包含什么吗?
-
关闭记事本 :)
标签: c# file stream delete-file