Console.WriteLine("Hello World"); FileStream fs1 = new FileStream("Test.txt", FileMode.Create); // First, save the standard output. TextWriter tmp = Console.Out; StreamWriter sw1 = new StreamWriter(fs1); Console.SetOut(sw1); Console.WriteLine("Hello file"); Console.SetOut(tmp); Console.WriteLine("Hello World"); sw1.Close();
设置到FileStream就是输出到文本文件,设置为Console.Out就是输出到命令行窗口
时间: 2024-12-06 09:36:43