追加和分割大于2GB的文件 [英] appending and splitting files larger than 2gb

查看:182
本文介绍了追加和分割大于2GB的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Visual Studio不允许您添加或拆分大于2GB的文件.

我正在尝试使用此方法附加文件.

Visual studio doesn''t allow you to append or split files larger than 2gb.

I''m trying to append a file using this method.

FileStream fsSource = new FileStream(OriginalFilePath, FileMode.Append);
Byte[] bytePart = System.IO.File.ReadAllBytes(Part2FilePath);
fsSource.Write(bytePart, 0, bytePart.Length);



如果文件Part2FilePath大于2gb,则会出现错误:
文件太长.此操作目前仅限于支持小于2 GB的文件."

我下载了一个可以做到的程序,所以我知道可以做到.我只是不知道是否可以在Visual Studio(C#)中使用.任何帮助,将不胜感激.谢谢.
Brian Cummings



If the file Part2FilePath is more than 2gb i get the error:
"The file is too long. This operation is currently limited to supporting files less than 2 gigabytes in size."

I downloaded a program that can do it so I know it can be done. I just don''t know if its possible with Visual Studio(C#). Any help would be appreciated. Thank.
Brian Cummings

推荐答案

您是否尝试过使用适当的Windows API函数而不是内置的File函数来打开它.这些可能没有限制(或可能有文件记录的限制).我建议您浏览一下Windows API文档,找到一个可能起作用的函数,然后查看此站点以了解如何使用它:

http://pinvoke.net/ [
Have you tried opening it with an appropriate Windows API function, instead of the built in File functions. These may not have the limit imposed (or may have a documented way around it). I suggest you have a look through the Windows API documentation, find a function that may work, and then look at this site to work out how use it:

http://pinvoke.net/[^]


是可以的-我相信,我还没有尝试过(我周围没有很多2Gb文件,和那些我不想做但我不想在一起的人

问题是您正在尝试通过File.ReadAllBytes在单个块中执行此操作,这(可以理解)限制为2Gb.

如果以100Mb的块读取它,那么系统将更容易处理并且可以正常工作.

请参阅
http://msdn.microsoft.com/en-us/library/system .io.filestream.read.aspx [ ^ ],就可以了.
Yes it can be done - I believe, I haven''t tried it (I don''t have many 2Gb files lying around, and those I do I don''t particularly want to but together)

The problem is that you are trying to do it in a single chunk, via File.ReadAllBytes, which is (understandably) limited to 2Gb.

If you read it in chunks of say 100Mb then that will be a lot easier for the system to handle and should work fine.

See http://msdn.microsoft.com/en-us/library/system.io.filestream.read.aspx[^] and you''ll be fine.


您必须在循环内以较小的块读取要附加到另一个文件的文件. .一个进程有2GB的限制(至少在32位计算机上).因此,如果该功能一次读取整个2GB,则该过程将耗尽内存.

除此之外:fSource在这里有点误导.它应该更像fDest,因为该文件句柄是目标位置或写操作. fSource应该是文件Part2FilePath.打开该文件,并以100-500MB的块读取它,然后将其附加到fDest.

最好的问候,
曼弗雷德(Manfred)
You have to read the file you want to append to the other in smaller chunks inside a loop. There is a limit of 2GB for one process (at least on 32bit machines). So if the function were to read the whole 2GB at once the process would run out of memory.

Besides that: fSource is a bit misleading here. It should be more like fDest since that file handle is the destination or the write operation. fSource should be the file Part2FilePath. Open that and read it in chunks of 100 - 500MB which you then append to fDest.

Best Regards,
Manfred


这篇关于追加和分割大于2GB的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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