I have a new file every few seconds that looks like this:
23
45
21
1
9
23
42
22
40
11
33
32
18
11
12
32
22
7
37
30
In this text file to be read there is one number per line that will be between 1-40. These files are generated several times a minute.
I am trying to order them ascending with StringReader
and StringWriter
. My logic must be flawed as nothing shows up in this file I intended to send it to. I passed true
as the append
parameter but still nothing is populated in my sorted file.
The goal was to read from the text file with the for
loop which iterates over 1-40 int values and compare that to each string or int from the file read and when found copy that from the read file into the sorted file in sorted order.
I have been looking at it for a while and it should work but does not. Would this be easier with the file reader/writer classes or streamreader/writer as I have done?
public static void ProcessDirectory()
{
int variable1;
StreamReader readToSort = new StreamReader(@"C:write.txt");
StreamWriter writeSorted = new StreamWriter(@"C:Sorted_File.txt", true);
for (int i = 1; i > 41; i++)
{
variable1 = (readToSort.Read());
while (!readToSort.EndOfStream)
{
if (variable1 == i)
{
writeSorted.Write(i.ToString() + "\n");
}
}
MessageBox.Show("processing #" + variable1);
}
readToSort.Close();
writeSorted.Close();
}