VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



This VB Express code demostrates how is possible to load binary files into byte arrays and how to c

by Dario B. (2 Submissions)
Category: Files/File Controls/Input/Output
Compatability: VB.NET
Difficulty: Unknown Difficulty
Originally Published: Tue 5th December 2006
Date Added: Mon 8th February 2021
Rating: (1 Votes)

This VB Express code demostrates how is possible to load binary files into byte arrays and how to convert and manipulate them as strings

Rate This VB Express code demostrates how is possible to load binary files into byte arrays and how to c




    'This is very important for loading and saving without corruption
    Dim enc As System.Text.Encoding = System.Text.Encoding.GetEncoding("iso-8859-1")

    'Load first file
    myArray = System.IO.File.ReadAllBytes("C:\file1.bin")
    s1 = enc.GetString(myArray)

    'Load second file and join the two contents
    Erase myArray
    myArray = System.IO.File.ReadAllBytes("C:\file2.bin")
    s2 = enc.GetString(myArray)

    'Concatenate using a custom separator
    s = s1 & "<MYSEPARATOR>" & s2

    'Save all in a new file
    Erase myArray
    myArray = enc.GetBytes(s)
    System.IO.File.WriteAllBytes("C:\joinedFiles.bin", myArray)

    'Reload the joined file
    myArray = System.IO.File.ReadAllBytes("C:\joinedFiles.bin")
    s = enc.GetString(myArray)

    'Rebuild the two original files
    Dim sp() As String = Split(s, "<MYSEPARATOR>")

    'Save first file 
    Erase myArray
    myArray = enc.GetBytes(sp(0))
    System.IO.File.WriteAllBytes("C:\newfile1.bin", myArray)

    'Save the second one 
    Erase myArray
    myArray = enc.GetBytes(sp(1))
    System.IO.File.WriteAllBytes("C:\newfile2.bin", myArray)

Download this snippet    Add to My Saved Code

This VB Express code demostrates how is possible to load binary files into byte arrays and how to c Comments

No comments have been posted about This VB Express code demostrates how is possible to load binary files into byte arrays and how to c. Why not be the first to post a comment about This VB Express code demostrates how is possible to load binary files into byte arrays and how to c.

Post your comment

Subject:
Message:
0/1000 characters