How do I read a binary file back into an Array?

I have written an Vector{UInt} into a binary file and I want to read the binary file back into a Vector{UInt}. How do I do that?

# write it out
bbc = rand(UInt8, 100)
io = open("io.test", "w")
write(io, bbc)
close(io)


# read back in
io = open("io.test", "r")
bbc_new = read(io, Vector{UInt})
close(io)

I get error

ERROR: The IO stream does not support reading objects of type Array{UInt64,1}.

Found a solution here.

bbc_new  = Array{UInt8,1}(undef, 100)

read!(io, bbc_new)

close(io)
1 Like