首页 > 解决方案 > 更改 File.Copy 默认缓冲区大小。

问题描述

我正在寻找可能提高文件传输到网络驱动器的速度的方法。我目前正在使用标准的 File.Copy。有谁知道 File.Copy 的默认缓冲区大小以及是否可以更改它?

标签: c#copybuffersystem.io.file

解决方案


鉴于File.Copy使用 Window 的复制功能,您可以在源代码中看到:

internal const String KERNEL32 = "kernel32.dll";

[DllImport(KERNEL32, SetLastError=true, CharSet=CharSet.Auto, BestFitMapping=false)]
[ResourceExposure(ResourceScope.Machine)]
internal static extern bool CopyFile(...)

...
bool r = Win32Native.CopyFile(fullSourceFileName, fullDestFileName, !overwrite);

您可以做很多事情来优化它(事实上,什么都没有)。


推荐阅读