c# - 创建文件后如何关闭文件

标签 c#

我是第一次用 C# 编写代码并遇到了这个问题。

我使用函数 File.WriteAllBytes(OutputFileName, dest);它正在磁盘上创建一个文件,当我的应用程序尝试使用 file.Open 打开同一文件时给我一个异常(exception)访问路径被拒绝。请帮我摆脱这个。我在 Windows 7 上,不是以管理员身份运行。

谢谢。

最佳答案

文件已关闭。由于其他原因被拒绝。检查路径,或者您可以使用 FileMode File.Open(path, FileMode.Open) 打开它。否则请检查您的权限。

Given a byte array and a file path, this method opens the specified file, writes the contents of the byte array to the file, and then closes the file.

Source

关于c# - 创建文件后如何关闭文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21426354/

相关文章:

C# 相当于 BigDecimal.stripTrailingZeros()

c# - 选项 405(不允许的方法)web api 2

c# - 同时请求会减慢 ASP Net Core API 的速度

c# - 按长度升序排序 List<List<string>>

c# - 将 PropertyInfo.PropertyType 转换为枚举

c# - 从代码执行事件

c# - Entity Framework 在更新时不更改 EnityState

c# - Visual Studio 2013 中没有 MVC 5 模板

c# - 如何在C#中用指针调用C语言编码的dll

c# - 如何解析来自 HttpClient 的 JSON 字符串?