Re: Commands Writing To Binary File

new topic     » goto parent     » topic index » view thread      » older message » newer message
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 
new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu