[問題] 請問文字檔太大OutOfMemoryException
不好意思,我所處理的IO文字檔是未格式化的
文字檔最少有1GB多,差不多有2千多萬行
我用ReadAllLines方式存在string變數裡
但執行確出現"OutOfMemoryException"
不知道有沒有高手可以幫忙~"~ 感謝萬分
DirectoryInfo di = new DirectoryInfo(System.Environment.CurrentDirectory + @"\
tm
List<String> _sub = new List<string>(); //宣告動態陣列
foreach (var fi in di.GetFiles("*", SearchOption.AllDirectories))
{ //tmp資料夾裡的文字檔都做處理
Console.WriteLine("準備中.....");
Console.WriteLine(System.Environment.NewLine);
foreach (string s in System.IO.File.ReadAllLines(di + fi.Name))
{//將檔案內容放置_sub陣列裡
_sub.Add(s);
counter++;
}
}
P.S: 光一個文字檔就有1GB多了;資料量非常龐大...
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 125.231.50.253
※ 文章網址: https://www.ptt.cc/bbs/C_Sharp/M.1513643689.A.CCD.html
→
12/19 09:09,
6年前
, 1F
12/19 09:09, 1F
→
12/19 09:10,
6年前
, 2F
12/19 09:10, 2F
→
12/19 09:13,
6年前
, 3F
12/19 09:13, 3F
不好意思,我用StreamReader也一樣
StreamReader sr =....
while(sr.ReadLine()!=null)
{
}
在六百多萬行就出現outofmemory
※ 編輯: takesi5200 (42.76.110.203), 12/19/2017 10:51:56
→
12/19 13:04,
6年前
, 4F
12/19 13:04, 4F
→
12/19 13:59,
6年前
, 5F
12/19 13:59, 5F
→
12/19 13:59,
6年前
, 6F
12/19 13:59, 6F
→
12/19 14:02,
6年前
, 7F
12/19 14:02, 7F
→
12/19 14:03,
6年前
, 8F
12/19 14:03, 8F
→
12/19 14:05,
6年前
, 9F
12/19 14:05, 9F
→
12/19 14:05,
6年前
, 10F
12/19 14:05, 10F
推
12/19 16:27,
6年前
, 11F
12/19 16:27, 11F
推
12/19 18:44,
6年前
, 12F
12/19 18:44, 12F
→
12/19 18:45,
6年前
, 13F
12/19 18:45, 13F
推
12/19 18:49,
6年前
, 14F
12/19 18:49, 14F
→
12/19 18:49,
6年前
, 15F
12/19 18:49, 15F
感謝各位前輩的指點,Initialize()釋放後己經解決此問題
List<String> _sub = new List<string>();
string[] readtext = System.IO.File.ReadAllLines(failpath);
foreach (string s in readtext)
{//將檔案內容放置_sub陣列裡
_sub.Add(s);
counter++;
readtext.Initialize();
}
※ 編輯: takesi5200 (125.231.50.253), 12/19/2017 21:37:21