ファイル読み書き

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

Dim inputFile As String = Path1 & file1 ' 入力用ファイル
Dim outputFile As String = Path1 & file2 ' 出力用ファイル

' 出力用ファイルをオープンする
Dim writer As New System.IO.StreamWriter(outputFile, False, System.Text.Encoding.GetEncoding("Shift_JIS"))

' 入力用ファイルをオープンする
Dim reader As New System.IO.StreamReader(inputFile, System.Text.Encoding.GetEncoding("Shift_JIS"))

' 読み取り可能文字が存在しない(ファイルの末尾に到着)すると -1 が返される
While (reader.Peek() > -1)

' 1 行ずつ読み込み、出力ファイルに書き込む
' このときの改行コードは Windows標準の CRLF となる
writer.WriteLine(reader.ReadLine())

End While

' ファイルを閉じる
reader.Close()

' ファイルを閉じる
writer.Close()

End Sub