美文网首页代码片段分享
xamarin 公共项目中 copy或move文件失败(And

xamarin 公共项目中 copy或move文件失败(And

作者: 花艺荣 | 来源:发表于2019-09-28 22:27 被阅读0次

问题:
权限是有的,创建以及删除都会成功,但使用move和copy方法时报错。
错误如下:

System.UnauthorizedAccessException: Access to the path is denied. 
---> System.IO.IOException: Operation not permitted

我的解决方法:
那就不用copy 或 copyto,使用文件读写来拷贝文件:


FileStream fs = new FileStream(fi.FullName, FileMode.Open, FileAccess.Read);
FileStream fsWrite = new FileStream(pathstr, FileMode.Create, FileAccess.Write);
byte[] tmpUploadBuffer = new byte[1024 * 128];
int bytes;
while ((bytes = fs.Read(tmpUploadBuffer, 0, tmpUploadBuffer.Length)) > 0)
{
    fsWrite.Write(tmpUploadBuffer, 0, bytes);
    fsWrite.Flush();
};
fs.Close();
fsWrite.Close();
           

说明:
如有其他解决方案请留言告知,在此多谢。

相关文章

网友评论

    本文标题:xamarin 公共项目中 copy或move文件失败(And

    本文链接:https://www.haomeiwen.com/subject/lnihuctx.html