C#/CopyFile:带有 Progress 的跨平台代码
请建议我一个 C# 跨平台解决方案来复制进度文件。 该方法应该能够在 Mono 以及 .NET 上复制文件。
PS 这里的大多数解决方案都是指 CopyFileEx (它使用 PInvoked,我不确定这是否适用于 Mono)
Please suggest me a C# cross-platform solution to copy a File with progress.
The method should be able to copy the file on Mono as well on .NET.
P.S. Most of the solutions here refers to CopyFileEx (which uses PInvoked and I am not sure if this will works on a Mono)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以在文件流之间手动复制,例如 MonoDevelop 的文件部署器,每 1k 块后有一个回调。
它可能比 File.Copy 慢一点,但如果进度回调是必需的,您就没有太多选择。对于 MonoDevelop 文件复制器,我们通过 FUSE 写入本地安装的远程文件系统。
You can manually copy between filestreams, like the CopyFile method in MonoDevelop's file deployer, which has a callback after every 1k chunk.
It's probably a fair bit slower than File.Copy, but if progress callbacks are essential you don't have much choice. In the case of the MonoDevelop file copier, we write to locally-mounted remote file systems via FUSE.
您尝试过 File.Copy 方法吗?我对单声道没有经验,但认为它应该有效。您将不得不担心文件路径,这与 API 不同。
Did you try File.Copy method? I have no experience with mono, but think that it should work. You will have to worry about file paths, which is different from API.
StreamWriter
应该可以工作:),通过
StreamReader
将数据加载到内存中,并通过StreamWriter
或BinaryWriter
写入。如果你想要的话,甚至还有 AsyncWrite :)我有一个在 Mono 上运行的自定义存档格式,使用上面提到的这些 API。对你来说应该没有什么不同。
StreamWriter
should work :),Load data into memory via
StreamReader
?, and write it viaStreamWriter
orBinaryWriter
. and there is even AsyncWrite if you want :)I have an Custom Archive Format that runs on Mono, using these API's mentioned above. should be no different for you.