.NET File.Create,此后无法删除文件 [英] .NET File.Create , can't delete file afterwards

查看:97
本文介绍了.NET File.Create,此后无法删除文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用方法: System.IO.File.Create()

创建文件后,它将仍然保留在进程中,我无法删除它。

After the file gets created, it still remains used by a process, and I can't delete it.

有什么想法可以更好地创建文件,应该是一个0byte的文件,然后以某种方式关闭并处置吗?

Any idea how I can better create the file, should be a 0byte file, and then somehow close and dispose?

推荐答案

JL,

您应该在using语句中包装对.Create的调用,以便.Create返回的FileStream返回将正确关闭。 IE:

You should wrap your call to .Create in a using statement so that the FileStream that .Create returns will be closed properly. IE:

using (File.Create("path")){...}

这篇关于.NET File.Create,此后无法删除文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆