星空网 > 软件开发 > ASP.net

c#创建文件( File.Create() )后对文件写操作出错的分析

在C#中,使用system.IO.File.Create()创建完一个文件之后,如果需要对这个文件进行写操作,会出现错误,提示你“这个文件正在被使用”。

原因是System.IO.File.Create()返回的是一个FileStream,这个需要关闭,才能对其创建的文件进行写操作。有两种方法:

1. 直接关闭,像这样:
System.IO.File.Create("the path of the file").Close();

2. 使用using自动关闭:

using(System.IO.File.Create("the path of the file"))
{
  //Can do something else or nothing
}




原标题:c#创建文件( File.Create() )后对文件写操作出错的分析

关键词:C#

C#
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。

特许金融分析师:https://www.goluckyvip.com/tag/42384.html
特许金融分析师考试:https://www.goluckyvip.com/tag/42385.html
特讯集团:https://www.goluckyvip.com/tag/42386.html
特讯跨境电商财税专家:https://www.goluckyvip.com/tag/42387.html
特种货物运输:https://www.goluckyvip.com/tag/42389.html
腾道外贸大数据:https://www.goluckyvip.com/tag/42390.html
“三蹦子”海外爆红如何复刻?新品牌出海红人营销的3个策略:https://www.kjdsnews.com/a/1836458.html
“泡泡机”在美国市场的(发明专利)侵权预警及规避办法649:https://www.kjdsnews.com/a/1836459.html
相关文章
我的浏览记录
最新相关资讯
海外公司注册 | 跨境电商服务平台 | 深圳旅行社 | 东南亚物流