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屋!
查看全文