Re: Commands Writing To Binary File
- Posted by Andy Mar 27, 2009
- 827 views
DerekParnell said...
Andy said...
Hey Guys,
I'm using Eu 4.0 and I heard that there was an easier to write data to a binary file. I'm wondering what the commands are, or how I would go about writing data to a binary file.
If all your data is in one sequence you can simply do this ...
-- Write data to file include std/serialize.e integer size = dump(myData, theFileName) if size = 0 then puts(1, "Failed to save data to file\n") else printf(1, "Saved file is %d bytes long\n", size) end if
And to read it back in ...
-- Read data from file include std/serialize.e sequence mydata = load(theFileName) if mydata[1] = 0 then puts(1, "Failed to load data from file\n") else mydata = mydata[2] -- Restored data is in second element. end if
Still a bit confused, but I'll try a few more things. Perhaps if I give some of my code, it will help.
global integer handle global sequence file integer data data = 1 file = "" procedure SaveFile() handle = open(file,"wb") if handle = -1 then puts(1,"Cannot write to file!\n") else file = write_file(handle,data) end if end procedure
This is just a crude example of what I want do. Is there something wrong that I am doing, cause I get an error when I do this, or rather when I go to try it, it crashes on me.