The three read commands are reading the first, the second and the third element of the file (and interpret them as Int32). That the values are in general different should not be a surprise.
Yes, after you finish reading the file, you should close it: f = open("numbers.dat") anInt = read(f, Int32) a_million_floats = read(f, Float64, 1_000_000) close(f) On Tue, Oct 25, 2016 at 10:46 PM, Aleksandr Mikheev <al.mikhee...@gmail.com> wrote: > Thank you very much, Michele! One more question, if you do not mind. If I > do something like this: > > f = open("numbers.dat") > > a = read(f, Int32) > > a = read(f, Int32) > > a = read(f, Int32) > > > then a is different each time. I believe I read something about that you > should use command close() each you opened something. Is this correct? > > > вторник, 25 октября 2016 г., 23:11:01 UTC+3 пользователь Michele Zaffalon > написал: >> >> You open the file in the correct way. To read the integer, do read(f, >> Int32) followed by read(f, Float64, 1_000_000) to read the million floats. >> See the manual at http://docs.julialang.org/en/r >> elease-0.5/stdlib/io-network/ >> >> On Tue, Oct 25, 2016 at 10:05 PM, Aleksandr Mikheev <al.mik...@gmail.com> >> wrote: >> >>> Hello, sorry if this question have already been asked, but I could not >>> find a similar thread. So, I have a .dat ("numbers.dat") file, which I >>> should open. I believe I should do something like this: >>> >>> f = open("numbers.dat") >>> >>> >>> And after that I tried to read it: >>> >>> readlines(f) >>> >>> >>> However, Julia writes the Error: "UnicodeError: invalid character >>> index". My tutor told me that this is a binary file, so what I need is a >>> binary read, such as fread in C/C++. I tried to read the >>> documentation, tried to google, but still cannot understand what should I >>> do. Also, a quote from my tutor, which can probably help you to understand >>> the problem better: "The first 4 bytes contain an integer (in this >>> case, 1,000,000) and then 1,000,000 floats of 8 bytes each". >>> >>> Thank you in advance! >>> >> >>