当前位置: 首页>>代码示例>>VB.NET>>正文


VB.NET Console.SetOut方法代码示例

本文整理汇总了VB.NET中System.Console.SetOut方法的典型用法代码示例。如果您正苦于以下问题:VB.NET Console.SetOut方法的具体用法?VB.NET Console.SetOut怎么用?VB.NET Console.SetOut使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Console的用法示例。


在下文中一共展示了Console.SetOut方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的VB.NET代码示例。

示例1: InsertTabs

' 导入命名空间
Imports System.IO

Public Module InsertTabs
    Private Const tabSize As Integer = 4
    Private Const usageText As String = "Usage: INSERTTABS inputfile.txt outputfile.txt"
   
    Public Function Main(args As String()) As Integer
        If args.Length < 2 Then
            Console.WriteLine(usageText)
            Return 1
        End If
      
        Try
            ' Attempt to open output file.
            Using writer As New StreamWriter(args(1))
                Using reader As New StreamReader(args(0))
                    ' Redirect standard output from the console to the output file.
                    Console.SetOut(writer)
                    ' Redirect standard input from the console to the input file.
                    Console.SetIn(reader)
                    Dim line As String = Console.ReadLine()
                    While line IsNot Nothing
                        Dim newLine As String = line.Replace("".PadRight(tabSize, " "c), ControlChars.Tab)
                        Console.WriteLine(newLine)
                        line = Console.ReadLine()
                    End While
                End Using
            End Using
        Catch e As IOException
            Dim errorWriter As TextWriter = Console.Error
            errorWriter.WriteLine(e.Message)
            errorWriter.WriteLine(usageText)
            Return 1
        End Try

        ' Recover the standard output stream so that a 
        ' completion message can be displayed.
        Dim standardOutput As New StreamWriter(Console.OpenStandardOutput())
        standardOutput.AutoFlush = True
        Console.SetOut(standardOutput)
        Console.WriteLine($"INSERTTABS has completed the processing of {args(0)}.")
        Return 0
    End Function 
End Module
开发者ID:VB.NET开发者,项目名称:System,代码行数:45,代码来源:Console.SetOut

示例2: FileStream

Console.WriteLine("Hello World")
Dim fs As New FileStream("Test.txt", FileMode.Create)
' First, save the standard output.
Dim tmp as TextWriter = Console.Out
Dim sw As New StreamWriter(fs)
Console.SetOut(sw)
Console.WriteLine("Hello file")
Console.SetOut(tmp)
Console.WriteLine("Hello World")
sw.Close()
开发者ID:VB.NET开发者,项目名称:System,代码行数:10,代码来源:Console.SetOut


注:本文中的System.Console.SetOut方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。