有没有办法读取部分大的文本文件? [英] Is there a way to read large text file in parts?

查看:99
本文介绍了有没有办法读取部分大的文本文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个大文件(60MB),我把文件读入一个字符串,并荫返回该字符串的另一种方法。



现在,当我读文件转换成一个字符串,它为系统内存不足的异常。



有没有办法在部分读取文件并将其追加到字符串?
如果不是有没有办法解决?



 的静态公共字符串序列化()
{
线的returnValue;
System.IO.FileInfo文件1 =新的FileInfo(@C:\file.txt);
的returnValue = System.IO.File.ReadAllText(file1.ToString());
}


解决方案

你如何读取文件马上 ?
。您可以使用StreamReader类,和读取由线(ReadLine方法)。
$ B $文件线b也可以从在每个文件中读取指定的字节量的读取操作(读取方法)


I have a large file(60mb) and I am reading the file into a string and Iam returning that string to another method.

Now when I am reading the file into a string its giving System out of memory exception.

Is there a way to read file in parts and append it to the string? If not is there a way around this?

static public string Serialize()
{
     string returnValue;
     System.IO.FileInfo file1 = new FileInfo(@"c:\file.txt");
     returnValue = System.IO.File.ReadAllText(file1.ToString());
}

解决方案

How do you read the file right now ? You could use the StreamReader class, and read the file line by line (ReadLine method).
You could also read a specified amount of bytes from the file on each read operation (Read method)

这篇关于有没有办法读取部分大的文本文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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