Reading BIN file of unknown size in Julia?

Viewed 45

I'm quite new to julia and struggling to figure out how to read a BIN file without knowing its size. The code below allows me to read a BIN file but I need to know the size of the file for it to work.

Is there a way to read the file without having to know its size before so I can run this code on multiple files?

    y = Array{Float32}(undef, (2017719)) 

    open("test_file.bin") do io
            read!(io, y)
    end

Thank you!

1 Answers

This will do what you want:

y = reinterpret(Float32, read("test_file.bin"))

The read call reads the data in as a byte vector and the reinterpret call reinterprets that data as 32-bit floats.

Related