JoinBinaryFiles – Joining a variable number of binary files into a single file

' Join a variable number of binary files into a single file'' Params:'  - resultFile: the complete path of the result file you want to create'  - sourceFiles: the sequence of files whose content will be joined together'' Example:'   JoinBinaryFiles("D:Test.bin", "D:Source1.bin", "D:Source2.bin",'  "D:Source3.bin")Sub JoinBinaryFiles(ByVal resultFile As String, ByVal ParamArray sourceFiles() _    As String)    ' if the result file already exists, delete it    If System.IO.File.Exists(resultFile) Then        System.IO.File.Delete(resultFile)    End If    ' create the destination file and open it in write mode    Dim fsw As New System.IO.FileStream(resultFile, _        System.IO.FileMode.CreateNew)    Dim writer As New System.IO.BinaryWriter(fsw)    ' open each input file in read mode, and copy its content to the     ' destination file    Dim fpath As String    For Each fpath In sourceFiles        Dim fsr As System.IO.FileStream        Dim reader As System.IO.BinaryReader        Try            ' create the reader for this file            fsr = New System.IO.FileStream(fpath, System.IO.FileMode.Open, _                System.IO.FileAccess.Read)            reader = New System.IO.BinaryReader(fsr)            ' read the binary content and write it to the destination file            writer.Write(reader.ReadBytes(fsr.Length))        Catch e As Exception            ' if there is an exception, close the writer and re-throw the             ' exception            ' so that the routines terminates. The reader is closed in the             ' Finally block below            writer.Close()            fsw.Close()            Throw e        Finally            If Not reader Is Nothing Then                reader.Close()                fsr.Close()            End If        End Try    Next    ' close the writer    writer.Close()    fsw.Close()End Sub

Share the Post:
Share on facebook
Share on twitter
Share on linkedin

Overview

The Latest

microsoft careers

Top Careers at Microsoft

Microsoft has gained its position as one of the top companies in the world, and Microsoft careers are flourishing. This multinational company is efficiently developing popular software and computers with other consumer electronics. It is a dream come true for so many people to acquire a high paid, high-prestige job

your company's audio

4 Areas of Your Company Where Your Audio Really Matters

Your company probably relies on audio more than you realize. Whether you’re creating a spoken text message to a colleague or giving a speech, you want your audio to shine. Otherwise, you could cause avoidable friction points and potentially hurt your brand reputation. For example, let’s say you create a

chrome os developer mode

How to Turn on Chrome OS Developer Mode

Google’s Chrome OS is a popular operating system that is widely used on Chromebooks and other devices. While it is designed to be simple and user-friendly, there are times when users may want to access additional features and functionality. One way to do this is by turning on Chrome OS