Writing to file-Reading from file?

BlitzMax Forums/BlitzMax Beginners Area/Writing to file-Reading from file?

The commands WriteInt etc. are for writing binary files, if you want to use text files (files you can read and write with text editors etc.) stick with the WriteLine / ReadLine commands.

Here is an example of writing and reading some integers to and from a text file:
Local x=20
Local y=40

out=WriteStream("test.txt")
If Not out RuntimeError "Failed to open a WriteStream to file test.txt"
WriteLine out,x
WriteLine out,y
CloseStream out

in=ReadStream("test.txt")
If Not In RuntimeError "Failed to open a ReadStream to file test.txt"
x1=Int(ReadLine(in))
y1=Int(ReadLine(in))
CloseStream in

Print "x1="+x1
Print "y1="+y1