-1
固定ファイルを経由してaを挿入するプログラムを作成しました。プログラムは正常に動作し、コンソールに正しく表示されます。問題は、ファイルの行に書き込むためにコンソールから行を取得できないことです。 すべての試みは、空のファイルで終わるか、個々の行として書かれた行の各文字列で終わります。次のコードは、出力をファイルに書き込む必要があるが、ファイルは空白のコードを示しています。.NET Console.WriteLine()Console.SetOut
Imports System.IO
Module Module1
Sub Main()
Dim stdFormat As Integer() = {3, 13, 11, 5, 2, 2, 13, 14, 30, 15, 76, 80, 95, 100, 50, 2, 10, 30}
Using MyReader As New FileIO.TextFieldParser("SOURCE.txt")
MyReader.TextFieldType = FileIO.FieldType.FixedWidth
MyReader.FieldWidths = stdFormat
Dim currentRow As String()
While Not MyReader.EndOfData
Try
Dim rowType = MyReader.PeekChars(3)
If String.Compare(rowType, "Err") = 0 Then
Else
MyReader.SetFieldWidths(stdFormat)
End If
currentRow = MyReader.ReadFields
For Each newString In currentRow
Console.Write(newString & "|")
Next
Dim file = New FileStream("test.txt", FileMode.Append)
Dim standardOutput = Console.Out
Using writer = New StreamWriter(file)
Console.SetOut(writer)
Console.WriteLine()
Console.SetOut(standardOutput)
End Using
Catch ex As FileIO.MalformedLineException
End Try
End While
End Using
Console.ReadLine()
End Sub
End Module