边读边处理,不要全部放到内存中 new Thread((ThreadStart)delegate { StreamReader sr = new StreamReader(FileName, Encoding.GetEncoding("gb2312")); int line = 0; string line= sr.ReadLine(); while (line!="") { line= sr.ReadLine(); } sr.Close(); }).Start();
分块读取吧。 不过,200M的TXT……
FileInfo fi = new FileInfo(filePath); FileStream fs = fi.OpenRead(); byte[] imageData = new byte[fi.Length]; fs.Read(imageData, 0, Convert.ToInt32(fi.Length)); fs.Close();有试过将600MB的文件读入,不过时间好长啊。
StreamReader sr = new StreamReader(@"D:\****");
string str = sr.ReadLine(); while (str!=null)
{
str = sr.ReadLine();
sb.Append(str);
}
textBox1.Text = sb.ToString();这样是不行的
StringBuilder sb = new StringBuilder();
StreamReader sr = new StreamReader(@"D:\****");
string str = sr.ReadLine(); List<string> strList = new List<string>();
int length = 1024 * 512;//在测试中自己调调大小 while (str != null)
{
str = sr.ReadLine();
sb.Append(str); if (sb.Length >= length)
{
strList.Add(sb.ToString().TrimEnd());
sb.Remove(0, sb.Length);
}
}
应该这样(200M*1024K*1024B)/2B
这下绝对正确了!太悲剧了,老了,记忆力减退了!
new Thread((ThreadStart)delegate
{
StreamReader sr = new StreamReader(FileName, Encoding.GetEncoding("gb2312"));
int line = 0;
string line= sr.ReadLine();
while (line!="")
{
line= sr.ReadLine();
}
sr.Close();
}).Start();
不过,200M的TXT……
FileStream fs = fi.OpenRead();
byte[] imageData = new byte[fi.Length];
fs.Read(imageData, 0, Convert.ToInt32(fi.Length));
fs.Close();有试过将600MB的文件读入,不过时间好长啊。
另外25楼wuyq11的方法也是不错的,内存占用不大,除非极端的情况出现,就是所有内容都在1行里,那就只能靠状态机了。