Is FileStream the safest way to copy a file vs. File.Copy?

安稳与你 提交于 2020-01-16 01:17:09

问题


I would like to copy the file from source to destination directory. I heard that it is best to do this with a FileStream in case it gets modified later / accessed later.

I am using C# 2.0 and .NET 2.x.

I don't need to determine if the file is open or not or read/write or not. I just need to copy it as is, I have already determined that the file has stopped growing (check every 4 seconds) so that is 'good enough' in my situation.

So should I use MemoryStream or FileStream or File.Copy(..) and How?


回答1:


Use: File.Copy(..)

How: See the documentation. Also, I recommend checking out the Path class.



来源:https://stackoverflow.com/questions/4959349/is-filestream-the-safest-way-to-copy-a-file-vs-file-copy

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!