Console.Out Property
.NET Framework 3.0
Gets the standard output stream.
Namespace: System
Assembly: mscorlib (in mscorlib.dll)
Assembly: mscorlib (in mscorlib.dll)
This property is set to the standard output stream by default. This property can be set to another stream with the SetOut method.
The following code example illustrates the use of the Out property.
public class InsertTabs { private const int tabSize = 4; private const string usageText = "Usage: INSERTTABS inputfile.txt outputfile.txt"; public static int Main(string[] args) { StreamWriter writer = null; if (args.Length < 2) { Console.WriteLine(usageText); return 1; } try { writer = new StreamWriter(args[1]); Console.SetOut(writer); Console.SetIn(new StreamReader(args[0])); } catch(IOException e) { TextWriter errorWriter = Console.Error; errorWriter.WriteLine(e.Message); errorWriter.WriteLine(usageText); return 1; } string line; while ((line = Console.ReadLine()) != null) { string newLine = line.Replace(("").PadRight(tabSize, ' '), "\t"); Console.WriteLine(newLine); } writer.Close(); // Recover the standard output stream so that a // completion message can be displayed. StreamWriter standardOutput = new StreamWriter(Console.OpenStandardOutput()); standardOutput.AutoFlush = true; Console.SetOut(standardOutput); Console.WriteLine("INSERTTABS has completed the processing of {0}.", args[0]); return 0; } }
public class InsertTabs
{
private static int tabSize = 4;
private static String usageText = "Usage: INSERTTABS inputfile.txt"
+ " outputfile.txt";
public static void main(String[] args)
{
StreamWriter writer = null;
if (args.length < 2) {
Console.WriteLine(usageText);
return ;
}
try {
writer = new StreamWriter(args[1]);
Console.SetOut(writer);
Console.SetIn(new StreamReader(args[0]));
}
catch (IOException e) {
TextWriter errorWriter = Console.get_Error();
errorWriter.WriteLine(e.get_Message());
errorWriter.WriteLine(usageText);
return ;
}
String line;
while (((line = Console.ReadLine()) != null)) {
String newLine = line.Replace("".PadRight(tabSize, ' '), "\t");
Console.WriteLine(newLine);
}
writer.Close();
// Recover the standard output stream so that a
// completion message can be displayed.
StreamWriter standardOutput = new StreamWriter(Console.
OpenStandardOutput());
standardOutput.set_AutoFlush(true);
Console.SetOut(standardOutput);
Console.WriteLine("INSERTTABS has completed the processing of {0}.",
args[0]);
} //main
} //InsertTabs
const tabSize = 4; const usageText = "Usage: INSERTTABS inputfile.txt outputfile.txt"; var writer : StreamWriter = null; var args = Environment.GetCommandLineArgs(); if (args.Length != 3) { Console.WriteLine(usageText); Environment.Exit(1); } try { writer = new StreamWriter(args[2]); Console.SetOut(writer); Console.SetIn(new StreamReader(args[1])); } catch(e : IOException) { var errorWriter = Console.Error; errorWriter.WriteLine(e.Message); errorWriter.WriteLine(usageText); Environment.Exit(1); } var line; while ((line = Console.ReadLine()) != null) { var newLine = line.Replace(("").PadRight(tabSize, ' '), "\t"); Console.WriteLine(newLine); } writer.Close(); // Recover the standard output stream so that a // completion message can be displayed. var standardOutput = new StreamWriter(Console.OpenStandardOutput()); standardOutput.AutoFlush = true; Console.SetOut(standardOutput); Console.WriteLine("INSERTTABS has completed the processing of {0}.", args[0]);
Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.