Quantcast
Viewing all articles
Browse latest Browse all 27229

Merging two txt files into new file

Hi there!
I'm working on an app that merges two txt files ( Input1.txt , Input2.txt ) and create a new file (Collection.txt).

What I did so far is this :
Code:

Public Class Form1

    Private Sub Btn1_Click(sender As Object, e As EventArgs) Handles Btn1.Click
        Dim fileReader As String
        fileReader = My.Computer.FileSystem.ReadAllText("C:\Users\Input1.txt")

        MsgBox(fileReader) 'showing the content in message box

        'creats new file + adds contents from input files
        Dim file As StreamWriter
        file = My.Computer.FileSystem.OpenTextFileWriter("c:\Users\Collection.txt", True)
        file.WriteLine(fileReader)
        file.Close()
    End Sub

    Private Sub Btn2_Click(sender As Object, e As EventArgs) Handles Btn2.Click
        Dim fileReader As String
        fileReader = My.Computer.FileSystem.ReadAllText("C:\Users\Input2.txt")
        MsgBox(fileReader) 'showing the content in message box

        'creats new file + adds contents from input files
        Dim file As StreamWriter
        file = My.Computer.FileSystem.OpenTextFileWriter("c:\Users\Collection.txt", True)
        file.WriteLine(fileReader)
        file.Close()

    End Sub

I'm using two button to read each file and save them to the new one!
My question is: How can I read & save both files at once? ( input1.txt + input2.txt )
So I only press one button only!!!
Thanks

Viewing all articles
Browse latest Browse all 27229

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>