c# - Read chosen line from CSV -
I have a large CSV file with approximately 1,000,000 lines and it takes about 500 MB of memory to read all the files. I do not need to read every hundred lines from the file. I try to do this through ReadLines
, but it's really slow, fast ReadAllLines
.
My code:
I read about some readers:
-
-
-
Has anyone got the solution? I want to read only a few lines from CSV, not a complete file.
readline
does not slow down The problem is that you can make the file every instance are rereading to the desired line (when I read = 0, you line 0-100 ... when I = 2, you read the line 0-200, etc.)
> You should refrain from calling file.ReadLines many times in other words, just open a file once and filter the rows you use where
Do not want to b Means try it:
var filteredLines = File.ReadLines ( "TestCSV.csv"). Select ((text, index) = & gt; new {text, index}). = & Gt; X.index% 100 == 0); Forchach (diversified line in filtered line) {table offstrength [line.index] = line. Text; }
Not sure how you are creating or using that code, tableOfString , but if it is completely to get these lines So you query directly to your linq array (you do not need to populate the array in the for-loop):
var tableOfString = File.ReadLines ("TestCSV.csv") . Where ((x, i) => i% 100 == 0) .oir ();
Comments
Post a Comment