FileStream是复制文件还是File.Copy的最安全方法吗?
我想将文件从源复制到目标目录.我听说最好使用FileStream进行此操作,以防日后对其进行修改/以后对其进行访问.
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.
我正在使用C#2.0和.NET 2.x.
I am using C# 2.0 and .NET 2.x.
我不需要确定文件是否打开或读取/写入.我只需要按原样复制它,我已经确定该文件已停止增长(每4秒检查一次),因此在我的情况下已经足够了.
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.
那么我应该使用MemoryStream还是FileStream或File.Copy(..)以及如何使用?
So should I use MemoryStream or FileStream or File.Copy(..) and How?
使用: File.Copy(..)
方法:请参阅文档.另外,我建议您检出 Path
类
How: See the documentation. Also, I recommend checking out the Path
class.