代码片段分享

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

2019-09-28  本文已影响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();
           

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

上一篇 下一篇

猜你喜欢

热点阅读