System.IO.IOException:在 C# 中共享路径冲突 [英] System.IO.IOException: Sharing violation on path in C#
本文介绍了System.IO.IOException:在 C# 中共享路径冲突的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用下面的代码将文件保存在 xamarin 形式的 ios 中,但给了我
I have used below code to save the file in xamarin forms ios but give me
System.IO.IOException:共享违规
System.IO.IOException: Sharing violation
请帮帮我.
FileStream fileStream = File.Open(pdfPath, FileMode.Create);
stream.Position = 0;
stream.CopyTo(fileStream);
fileStream.Flush();
fileStream.Close();
推荐答案
您是否检查过您的应用是否具有访问系统文件的权限?另外,在使用 File.Exists();
打开文件之前,我会检查一下文件是否存在.
Have you checked that your app has permission for accessing files on the system? Also i would to a check to see if the files exist before opening it with File.Exists();
.
在 C# 中还有更好的读取和写入文件的方法:
Also there are better ways of reading and writing to files in C#:
string path = Environment.GetFolderPath(Environment.SpecialFolder.Personal);
string filename = Path.Combine(path, "myfile.txt");
using (var streamWriter = new StreamWriter(filename, true))
{
streamWriter.WriteLine(DateTime.UtcNow);
}
using (var streamReader = new StreamReader(filename))
{
string content = streamReader.ReadToEnd();
System.Diagnostics.Debug.WriteLine(content);
}
这篇关于System.IO.IOException:在 C# 中共享路径冲突的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文