Hello to all, I'm trying to use the function below to print strings to a file. When I use Console.Write() or
Console.WriteLine() the output file grows up 3MB or 4MB per seconds, but when I try to use StreamWriter or
File.AppendAllText the output in the way shown below, the file grows up only in 20KB or 30KB per second.
Why the print speed decreases too much when I use StreamWriter instead of Console.WriteLine()?
What method should I use to write to a file maintaining the same speed of Console.WriteLine()?
public static void PrintFunction()
{
//using (StreamWriter writer = File.AppendText(@"C:\OuputFile.txt"))
using (StreamWriter writer = new StreamWriter(@"C:\OuputFile.txt", true))
{
//Console.Write("This is "); // Print speed is about 3MB-4MB per second
writer.Write("This is "); //Print decreases to 20KB-30KB per second
//File.AppendAllText(@"C:\OuputFile.txt", "This is "); Print decreases to 20KB-30KB per second
// SOME CODE
// SOME CODE
//Console.WriteLine("the first line"); // Print speed is about 3MB-4MB per second
writer.WriteLine("the first line"); // Print decreases to 20KB-30KB per second
//File.AppendAllText(@"C:\OuputFile.txt", "the first line"); // Print decreases to 20KB-30KB per second
}
}
Thanks in advance.