大文件到字节数组。 [英] Large file into byte array.

查看:117
本文介绍了大文件到字节数组。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

地狱



我将大文件转换为数组字节,但它显示OutofMemory Exception。



文件大小为750 MB。



我的操作系统: - 32位

内存: - 4 GB

框架: - 4.5

代码: -

byte [] encryptedData = new byte [832615276];



它显示错误。



任何替代解决方案所以请告诉我。



初始化字节数组时出现错误。有任何尺寸限制吗?





谢谢。



我尝试过:



byte [] encryptedData = new byte [832615276];

Hell

I am converting large file into byte of array but it showing OutofMemory Exception.

The File size is 750 MB.

My OS :- 32bit
RAM :- 4 GB
Framework :- 4.5
Code:-
byte[] encryptedData = new byte[832615276];

It showing Error.

Any alternate solution so please let me know.

Errors comes when initialize the byte array. Is there any size limit ?


Thanks.

What I have tried:

byte[] encryptedData = new byte[832615276];

推荐答案

尝试:

Try:
byte[] data = File.ReadAllBytes(pathToFile);



如果这给你带来了问题,那么你可能需要检查你的代码在做什么,因为一个数组最多可以达到2GB。 750MB应该没问题。



如果你不能把它作为一个完整的项目加载,那么考虑将它加载为FileStream - 你可以在块和大多数解密方法有一个接受流的方法。


If that gives you problems, then it may be that you need to check what else your code is doing, as an array can be up to 2GB. 750MB should be no problem at all.

If you can't load it as a complete item, then consider loading it as a FileStream - you can read that in "chunks" and most decryption methods have a method accepting streams.


这里的一些见解: c# - 对.Net数组大小的限制 - 堆栈溢出 [ ^ ]。
Some insight here: c# - The Limitation On the Size of .Net Array - Stack Overflow[^].


这篇关于大文件到字节数组。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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