FileStream是复制文件还是File.Copy的最安全方法吗? [英] Is FileStream the safest way to copy a file vs. File.Copy?

查看:78
本文介绍了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.

这篇关于FileStream是复制文件还是File.Copy的最安全方法吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆