c# - Manipulating input and output streams from one file to another -
c# - Manipulating input and output streams from one file to another -
i have new file every few seconds looks this:
23 45 21 1 9 23 42 22 40 11 33 32 18 11 12 32 22 7 37 30
in text file read there 1 number per line between 1-40. these files generated several times minute.
i trying order them ascending stringreader
, stringwriter
. logic must flawed nil shows in file intended send to. passed true
append
parameter still nil populated in sorted file.
the goal read text file for
loop iterates on 1-40 int values , compare each string or int file read , when found re-create read file sorted file in sorted order.
i have been looking @ while , should work not. easier file reader/writer classes or streamreader/writer have done?
public static void processdirectory() { int variable1; streamreader readtosort = new streamreader(@"c:write.txt"); streamwriter writesorted = new streamwriter(@"c:sorted_file.txt", true); (int = 1; > 41; i++) { variable1 = (readtosort.read()); while (!readtosort.endofstream) { if (variable1 == i) { writesorted.write(i.tostring() + "\n"); } } messagebox.show("processing #" + variable1); } readtosort.close(); writesorted.close(); }
to create sure correctly understand problem trying solve, made list of requirements based on question , comments below it.
your input consists of text files several gigabytes large, , hence cannot loaded memory these text files consist of numeric values only, each value beingness on own line these numeric values need written output file, in sorted orderit's not exclusively clear me input consists of might need right me here. need combine multiple (smaller) input files, sort combined contents, , output single (larger) file?
example:
input: file1_unsorted.txt (6gb), file2_unsorted.txt (6gb) output: file1_and_file2_sorted.txt (12gb)if so, each individual file little plenty loaded in memory (but not combined whole?)
example (assuming 1gb ram):
input: file1_unsorted.txt (600mb), file2_unsorted.txt (600mb), ..., file10_unsorted.txt (600mb) output: file1_through_file10_sorted.txt (6gb)or, can each individual input file big plenty not fit in memory, , these files each need sorted corresponding output file?
example:
input: file_unsorted.txt (6gb) output: file_sorted.txt (6gb)assuming both (unsorted) input , (sorted) output files big fit memory, need way sort contents of these files in chunks. keyword looking external sort.
here illustration of on codeproject (with source code , explanation): sorting huge text files
a similar stackoverflow question might want into: reading big text files streams in c#
if need help actual implementation, please provide additional info on input , (desired) output looks like. files big upload - screenshot of directory input , output files work. (and others) can see how big each file , grade (if @ all) need aggregated.
c# sorting text streamreader streamwriter.write
Comments
Post a Comment