[RESOLVED] [2005] Binary reader and peekchar
I've seen some code where if you have a particular sequence that is written by binarywriter --
Code:
bw.write(var1)
bw.write(var2)
and read by binaryreader --
var1 = br.readstring()
var2 = br.readint32()
that doesn't include a peekchar in the read code.
If you read the file in sequence exactly as written, do you need the peekchar?
Other code I've seen includes it --
Code:
Do while br.peekchar <> -1
read
read
loop
Also, another question about binarywriter --
I'm using the save file dialog to save my binary file so I can use any filename I choose.
I'm unsure about the file extension part of things though.
If i just pick a filename, I don't see where there's an extension automatically assigned (not that it's supposed to do that in savefiledialog) -- I have been using filename.bin
-- but I also saw an extension of filename.dat written in binary?
THANKS
Re: [2005] Binary reader and peekchar
The reason you use PeekChar is so you know when there is no more data to read, so you don't try to read past the EOF. If you already know exactly how much data there is to read in the file then there's no need to call PeekChar because you won't read past the EOF anyway.
File extensions have no effect on the file itself. They are just like a label on a jar. They are supposed to tell someone looking at it what is in the container but the label doesn't actually change the contents in anyway. Putting a label reading "Sugar" on a jar of salt doesn't magically make it sweet. You can put any extension you like on the file but "bin" (binary) and "dat" (data) are common choices for binary files. If you check out the properties of the SaveFileDilaog you'll see that it can be made to add a default extension if the user omits one.
Re: [2005] Binary reader and peekchar
Thanks much.
I can leave peekchar out in my case.
AND, thanks for the tip on the savefiledialog -- I forgot about that.