Reading and Write specific lines to text file C# -
i have master file called filename ids of people. in sorted order. want divide ids 27 chunks , copy each chunk different text file.
using (filestream fs = file.open(filename, filemode.open, fileaccess.read, fileshare.readwrite)) { string line; int numoflines = file.readalllines(filename).length; -- have 73467 int eachsubset = (numoflines / 27); var lines = file.readalllines(datafilename).take(eachsubset); file.writealllines(filename1,lines); }
i have 27 different text files. want 73467 of ids divided equally , copied on 27 different files. so, 1st file have id#1 id#2721 2nd dile have id#2722 id#(2722+2721) , on. not know how automate , run quickly.
thanks hr
the simplest way run file.readline , writeline inside loop , decide file receive line.
i wouldn't recommend parallelize routine since it's io operation, copy of lines pretty fast.
Comments
Post a Comment