Help with file operations please.

Blitz3D Forums/Blitz3D Beginners Area/Help with file operations please.

Galdy(Posted 2011) [#1]
Could some one show a simple code example for B3d of creating a file, writting both numerical data and string data, and then ofcourse reading it back. Please don't jumble it into a function at this point. If you could also keep the string data and numerical data examples separate .

Thanks,
Galdy

Last edited 2011

Last edited 2011


Matty(Posted 2011) [#2]
graphics 800,600,0,2
outfile=writefile("test.dat")
if outfile=0 then runtimeerror("could not open file for writing")
writeint outfile,123456
writefloat outfile,123.456
writestring outfile,"abcdefg"
closefile outfile

infile=readfile("test.dat")
if infile=0 then runtimeerror("could not open file for reading")
;make sure it is read in in the same order it was written
myint=readint(infile)
myfloat#=readfloat(infile)
mystring$=readstring(infile)

text 0,0,myint
text 0,20,myfloat
text 0,40,mystring
flip
waitkey
end




Galdy(Posted 2011) [#3]
Thanks Matty. That will hellp a bunch!